PHP file
Copy the Code code as follows:
Class xpathextension{
public static function Getnodes ($domDoc, $xpathString) {
$XP = new Domxpath ($DOMDOC);
$xp->registernamespace (' x ', ' http://www.w3.org/1999/xhtml ');
$xp->registernamespace (' xhtml ', ' http://www.w3.org/1999/xhtml ');
$xp->registernamespace (' i18n ', ' http://apache.org/cocoon/i18n/2.1 ');
$ret = Array ();
$nodes = $xp->query ($xpathString);
foreach ($nodes as $node) {
Array_push ($ret, $node);
}
return $ret;
}
}
$domDoc = new DOMDocument ();
$domDoc->load ("X1.xml");
$xpathString = "//xml/products/product/description";
$domNodeList = Xpathextension::getnodes ($domDoc, $xpathString);
echo count ($domNodeList);
foreach ($domNodeList as $domNode) {
Echo $domNode->nodevalue;
}
?>
Xml
Copy the Code code as follows:
Abcd
The above describes the Export_symbol PHP read XML instance code, including the content of Export_symbol, I hope the PHP tutorial interested in a friend to help.