php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40500 previousSibling not giving the correct element
Submitted: 2007-02-15 19:23 UTC Modified: 2007-02-15 19:57 UTC
From: schalk at unf dot edu Assigned: rrichards (profile)
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.1 OS: Mac OSX 10.4.8
Private report: No CVE-ID: None
 [2007-02-15 19:23 UTC] schalk at unf dot edu
Description:
------------
When I use previousSibling to get values of elements at the same level in the tree it does not work as expected.  Seems to need 2x the previousSibling calls to get to the right node. Seems to be adding in extra return characters (see actual result).

Note:
   echo "Found ".$entry->previousSibling->previousSibling->previousSibling->previousSibling->nodeValue." by ".$entry->previousSibling->previousSibling->nodeValue."<br>\n";

produces the correct result!

Reproduce code:
---------------
<?php
$xml= new DOMDocument();
$xml->load('http://fad.coas.unf.edu/animl/jcamp/xpathtest.xml');

$xpath = new DOMXPath($xml);
$entries = $xpath->query('/book/chapter/para/informaltable/tgroup/tbody/row/entry[. = "en"]');

foreach ($entries as $entry)
{
   echo "Found ".$entry->previousSibling->previousSibling->nodeValue." by ".$entry->previousSibling->nodeValue."<br>\n";
}

Expected result:
----------------
Found The Grapes of Wrath by John Steinbeck<br>
Found The Pearl by John Steinbeck<br>

(returned web page source code)

Actual result:
--------------
Found John Steinbeck by 
       <br>
Found John Steinbeck by 
       <br>

(returned web page source code)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-15 19:41 UTC] tony2001@php.net
For some reason I think it has nothing to do with PHP.
Rob, am I right?
 [2007-02-15 19:53 UTC] schalk at unf dot edu
Ignore this....
I did not set $xml->preserveWhiteSpace=false;

You can close this, sorry!
 [2007-02-15 19:57 UTC] tony2001@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC