PHP processing complex XML Data sample _php Tips

Source: Internet
Author: User

The examples in this article describe how PHP handles complex XML data. Share to everyone for your reference, specific as follows:

<?php $xml = <<< xml <?xml version= "1.0" encoding= "Utf-8"?> <epp "xmlns= urn:ietf:params:xml:ns": epp-1.0 "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Urn:ietf:params:xml:ns: epp-1.0 epp-1.0.xsd "> <response> <result code=" 1000 "> <msg>command completed successfully</m sg> </result> <resData> <domain:chkdata xmlns:domain= "urn:ietf:params:xml:ns:domain-1.0" Xsi:sche malocation= "urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd" > <domain:cd> <domain:name avail= "0" > qq.com</domain:name> <domain:reason>domain exists</domain:reason> </domain:cd> <do Main:cd> <domain:name avail= "1" >baidu.com</domain:name> <domain:reason>domain exists</do main:reason> </domain:cd> </domain:chkData> </resData> <trID> <cltrid>req-0 01-0000000074</cltrid> <svtrid>649334436-1440642163169</svtrid> </trID> </response> </epp> XML;
$x = simplexml_load_string ($xml);
Echo intval ($x->response->result["Code"]), "\ n";
Echo strval ($x->response->result->msg), "\ n";
$ns = $x->response->resdata->getnamespaces (true);
$cds = $x->response->resdata->children ($ns ["Domain"])->chkdata->cd; foreach ($cds as $key => $value) {echo intval ($value->name->attributes () ["Avail"]), Strval ($value->name), S
Trval ($value->reason), "\ n";

 }

More about PHP Interested readers can view the site topics: "PHP for XML file Operation skills Summary", "PHP error and Exception handling method summary", "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, " Summary of PHP operation and operator usage, "Summary of PHP Network programming skills", "Introduction to PHP Basic Grammar", "PHP Introduction to Object-oriented Programming", "Php+mysql Database Operation Introduction" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.