xpath to get all elements
I am using simplexml to parse开发者_开发知识库 xml and I can get single node but not all nodes i want
example
$xmlObject = simplexml_load_file($xml_file); // load the xml file
$cols = $xmlObject->RESULTSET->ROW->COL;
foreach ( $cols as $COL) {
echo $COL->DATA;
}
only gives me the first col of the first row, i tried
$xmlObject = simplexml_load_file($xml_file); // load the xml file
$cols = $xmlObject->xpath('*//COL');
foreach ( $cols as $COL) {
echo $COL->DATA;
}
and got nothing back
any idea what I might be doing wrong ?
<?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<RESULTSET FOUND="445">
<ROW MODID="45" RECORDID="1">
<COL>
<DATA>Integrating Ethanol</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>train track and gas pump</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>1.jpg</DATA>
</COL>
<COL>
<DATA/>
</COL>
</ROW>
<ROW MODID="29" RECORDID="3">
<COL>
<DATA>Keeping in Balance</DATA>
</COL>
<COL>
<DATA>21</DATA>
</COL>
<COL>
<DATA>book cover of Sweet Invisible Body</DATA>
</COL>
<COL>
<DATA/>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>
You can try with the following XPath expression which ignores the namespace:
//*[local-name() = 'COL']
This expression selects all nodes with name 'COL' no matter in what namespace the node is in.
The right xpath for this would be
//COL
without the
*
I think your problem might be that XML namespace, which was causing the problem for me when I ran the XML through this tool that I found using Google: http://www.xmlme.com/XpathTool.aspx
精彩评论