PHP parsing XML format documents

Source: Internet
Author: User

<?php
The first thing to do is to build a DOMDocument object
$xml = new DOMDocument ();
Loading an XML file
$xml->load ("3.xml");
Get all the post labels
$postDom = $xml->getelementsbytagname ("PROPERTIES");
Print_r ($postDom);
Echo ' <br> ';
Looping through post labels
foreach ($postDom as $post) {//Get title Tag node
$id = $post->getelementsbytagname ("Wcmmetatablehcn_services_supportsid"); /** * To get the id attribute of the title tag, go to section two * 1. Gets a list of all the attributes in the title, which is $title->item (0)->attributes * 2. Gets the attribute of the ID in the title, because it is in the first place so with item (0) * Small hint: * If the value of the attribute can be used with item (*)->nodevalue * If the tag of the attribute can be used with item (*)->nodename * You can use item (*)->nodetype * * If the type of attribute is taken.
$dataid = $post->getelementsbytagname ("METADATAID");
$time = $post->getelementsbytagname ("Crtime");
$title = $post->getelementsbytagname ("DocTitle");
$sub = $post->getelementsbytagname ("Bigtxt");
echo "Id:". $id->item (0)->nodevalue. "< br/>";
echo "Time:". $time->item (0)->nodevalue. "< br/>";
echo "Title:". $title->item (0)->nodevalue. "< br/>";
echo "Sub:". $sub->item (0)->nodevalue. "< br/>";

}
?>

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.