xml file parsing problem_PHP tutorial

WBOY
Release: 2016-07-13 10:51:42
Original
803 people have browsed it




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.

. . . . . .

title11
link12
dddddd
222222


">
title21
link22
aaaaaa
333333




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.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632549.htmlTechArticlexml file parsing problem I want to parse the following xml file and obtain title1, title2, xm:ce, xm:bt corresponding value. . . . . . . title11 link12 dddddd 222222 "> title21 link22 aaaaaa...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template