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.