如果我不知道他的节点集,我该如何使用XPath文档对象?我正在使用对libCurl的Php支持来抓取远程网页:
$source = curlGet( "http://www.foo.com" );
function curlGet( $url ) {
$ch = curl_init(); // Initialising
// Setting cURL options
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_USERAGENT, USR_AGENT );
$results = curl_exec( $ch ); // Executing cURL session
curl_close( $ch ); // Closing cURL session
return $results;
}
$domobject = returnXPathObject( $source );
/* Function to return XPath object */
function returnXPathObject( $item ) {
// Instantiating a new DomDocument object
$xmlPageDom = new DomDocument();
//Loading the HTML from downloaded page
@$xmlPageDom->loadHTML( $item );
// Istantiating new XPath DOM object
$xmlPageXPath = new DOMXPath( $xmlPageDom );
// Returning XPath object
echo $xmlPageXPath.'\n';
return $xmlPageXPath;
}
现在,从DOM对象的远程页面开始创建了哪些节点?我想将对象的内容转储到XML文件。对不起这个愚蠢的问题我很抱歉。