xml file parsing problem
I want to parse the following xml file and obtain the values corresponding to title1, title2, xm:ce, and xm:bt.
. . . . . .
The code looks like this:
$doc = new DOMDocument();
$doc->load( "testFile.xml" );
$itemtags = $doc->getElementsByTagName( "item" );
foreach( $itemtags as $itemtag )
{
$titles = $itemtag->getElementsByTagName( "title1" );
$title = $titles->item(0)->nodeValue;
$links = $itemtag->getElementsByTagName( "title2" );
$link = $links->item(0)->nodeValue;
//$dctags = $itemtag->getElementsByTagName( "xm:ce" );
//$dctag = $dctags->item(0)->nodeValue;
echo "$title - $link - $dctag n";
}
The problem now is that the values corresponding to title1 and title2 can be obtained,
But the values corresponding to xm:ce and xm:bt cannot be obtained,
Using this code, the object obtained by $itemtag->getElementsByTagName( "xm:ce" ); will definitely be empty.
Please tell me how to get the corresponding values of xm:ce and xm:bt?
Best answer[url=http://www.111cn.cn/bbs/space.php?username=volew]Link tag volew[/url]
[url=http://www.111cn.cn/bbs/space.php?uid=94211]Link tag[img]http://www.111cn.cn/server/avatar.php?uid=94211&size=small[ How about /img][/url]simplexml_load_file? You can read this.
D8888D reply content------------------------------------------------- ----------
What about simplexml_load_file? You can read this.
D8888D reply content------------------------------------------------- ----------
Use regular expressions
D8888D reply content------------------------------------------------- ----------
Doesn't anyone have any more suggestions?
D8888D reply content------------------------------------------------- ----------
Yeah, Baidu has it ready!
D8888D reply content------------------------------------------------- ----------
The problem has been solved, volew is the same as my current method. I'll post the code later.
D8888D reply content------------------------------------------------- ----------
$rdf = simplexml_load_file("http://www.test.com/index.rdf");
$arr = array();
$i = 1;
while (isset($rdf->item[$i]->title)) {
$arr['item'][$i]['title1'] = htmlspecialchars($rdf->item[$i]->title1);
$node = $rdf->item[$i]->children('http://purl.org/dc/elements/1.1/');
$arr['item'][$i]['ce'] = htmlspecialchars($node->ce);
$arr['item'][$i]['bt'] = htmlspecialchars($node->bt);
$i++;
}
$i--;
foreach ($arr['item'] as $item) {
print $item['ce']."----".$item['bt']. "
";
}
This is probably the processing process, there is no detailed arrangement, haha!
If there are any errors, please correct me.