Xml file parsing problems. For xml file parsing problems, I want to parse the following xml file and get the corresponding values of title1, title2, xm: ce, xm: bt ....... Title11link12dddddd222222title21link22aaaaaa xml file parsing
I want to parse the following xml file and get the values of title1, title2, xm: ce, xm: bt.
......
Title11
Link12
Dddddd
222222
">
Title21
Link22
Aaaaaa
333333
The code is as follows:
$ 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 is that the values of title1 and title2 can be obtained,
However, values corresponding to xm: ce and xm: bt cannot be obtained,
With this code, $ itemtag-> getElementsByTagName ("xm: ce"); the retrieved object must be empty.
How can I obtain the values corresponding to 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 [/img] [/url] simplexml_load_file? This can be read.
D8888D reply content -------------------------------------------------------
How about simplexml_load_file? This can be read.
D8888D reply content -------------------------------------------------------
Use regular expressions
D8888D reply content -------------------------------------------------------
No one gives me some suggestions!
D8888D reply content -------------------------------------------------------
Ah, Baidu, there are ready-made!
D8888D reply content -------------------------------------------------------
The problem has been solved. volew is the same as my current method. I will 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 process. I haven't sorted it out in detail!
If any error occurs, please correct it.
Parse I want to parse the following xml file and get the values of title1, title2, xm: ce, xm: bt. ...... Title11 link12 dddddd 222222 "> title21 link22 aaaaaa...