Php reads the xml instance code. The PHP file copy code is as follows :? PhpclassxpathExtension {publicstaticfunctiongetNodes ($ domDoc, $ xpathString) {$ xpnewnewdomxpath ($ domDoc); $ xp-registerNamespace (x, ht
Php file
The code is as follows:
Class xpathExtension {
Public static function getNodes ($ domDoc, $ xpathString ){
$ Xp = new DOMXPath ($ domDoc );
$ Xp-> registerNamespace ('X', 'http: // www.w3.org/5o/xhtml ');
$ Xp-> registerNamespace ('xhtml ', 'http: // www.w3.org/5o/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
The code is as follows:
Abcd
The pipeline code is as follows :? Php class xpathExtension {public static function getNodes ($ domDoc, $ xpathString) {$ xp = new DOMXPath ($ domDoc); $ xp-registerNamespace ('X', 'ht...