DOMXPath->query() ...
Posted: Tue Jan 24, 2006 3:13 pm
XML snippet I'm trying to query on:
XPath Query I'm trying to use: //FormattedReportObject[@FieldName='{Kit.EngrChgOrder}']/FormattedValue
The query works on the XML when I tried it with an online XPath tool. It does not work when I try the following:
If I do some stupidly simple query like //@*/.. it works fine, and I get tons of output. But any query that uses element names returns nothing, even though it works on the aforementioned online XPath tool. There are no errors generated... the formatting of the XML itself kind of sucks, but there's nothing I can do about that.
I am, once again, stumped. Any ideas?
Code: Select all
<FormattedSection SectionNumber="1">
<FormattedReportObjects>
<FormattedReportObject FieldName="{Kit.EngrChgOrder}">
<ObjectName>Field32</ObjectName>
<FormattedValue>SNAME</FormattedValue>
<Value>Some Name</Value>
</FormattedReportObject>
<!-- SNIP -->
</FormattedReportObjects>
</FormattedSection>The query works on the XML when I tried it with an online XPath tool. It does not work when I try the following:
Code: Select all
<?php
$file = 'C:/php5/apps/xmlReport/data/test.xml';
$data = new DOMDocument();
$data->load($file);
//load failure check snipped, I know it's loading fine
$xpath = new DOMXPath($data);
$query = "//FormattedReportObject[@FieldName='{Kit.EngrChgOrder}']/FormattedValue";
$result = $xpath->query($query);
foreach($result as $node) {
print_r($node->nodeValue);
}I am, once again, stumped. Any ideas?