Xml file parsing question _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.