kimisshao / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

XML XPATH issues #170

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the following XML Document:
<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" 
xmlns:d="urn:schemas:httpmail:" xmlns:c="xml:" xmlns:a="DAV:">
  <a:contentrange>0-2</a:contentrange>
  <a:response>
    <a:href>http://xxx/Exchange/xx/Inbox/test.EML</a:href>
    <a:propstat><a:status>HTTP/1.1 200 OK</a:status>
    <a:prop>
      <a:displayname>test.EML</a:displayname>
      <d:subject>test</d:subject>
    </a:prop>
  </a:response>
  <a:response>
    <a:href>http://xxx/Exchange/xxx/Inbox/test2.EML</a:href>
    <a:propstat><a:status>HTTP/1.1 200 OK</a:status>
    <a:prop>
      <a:displayname>test2.EML</a:displayname>
      <d:subject>test2</d:subject>
    </a:prop>
  </a:response>
</a:multistatus>

2. Then iterate over all a|response elements, and do a find on a|href

// load the xml doc
$doc = $doc = phpQuery::newDocumentXML($xml);

// register namespaces in doc
$doc->xpath->registerNamespace('a', 'DAV:');
$doc->xpath->registerNamespace('b', 
'urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/');
$doc->xpath->registerNamespace('c', 'xml:');
$doc->xpath->registerNamespace('d', 
'http://schemas.microsoft.com/mapi/proptag/');

// iterate over all a|response
foreach(pq('a|multistatus a|response') as $r) {
  $response = pq($r);
  $href = $response->find('a|href'); // Here $href returns no elements
  echo $href->xmlOuter(); // so this echos an empty string
}

What is the expected output? What do you see instead?
$href inside the loop should have returned the first a|href element inside each 
a|response element from the xml document

What version of the product are you using? On what operating system?
PHPQuery latest in pear channel 0.9.5
php 5.2.8
32bit windows xp

Please provide any additional information below.

I did find a solution to this issue in my particular case, but I do not know if 
this breaks other documents...
on file phpQueryObject.php at line 3067:

    ? "*[local-name()='{$node->tagName}'][{$i}]"

I replaced it with:

    ? "{$node->tagName}[{$i}]"

and a|href was found with no issues, no other queries in my app were affected 
either.

Original issue reported on code.google.com by fusianme...@gmail.com on 27 Jan 2011 at 6:43