, PHP parses XML with namespaces?

Source: Internet
Author: User
The XML file has axis generated:




{"Code": "2", "Message": "Enterprise name and Enterprise registration number Match"}





I want to get the content of Ns1:checkqyreturn.
How can I get it with PHP?


Reply to discussion (solution)

You can use the new simplexmlelement to resolve

$x = new SimpleXMLElement ($STR);  foreach ($x->entry as $t) {      echo $t->id. "
"; Echo $t->updated. "
"; $namespaces = $t->getnamespaces (true); $GD = $t->children ($namespaces [' ns1 ']); Echo $GD->phonenumber;


Reference: http://www.neatstudio.com/show-1549-1.shtml


You can use the new simplexmlelement to resolve

The namespace was tried, but the last converted JSON was parsed.
$xmlstr = preg_replace ('/\sxmlns= ' (. *?) " /', ' _xmlns= ' ${1} "', $simple);
$xmlstr = Preg_replace ('/< (\/)? ( \w+):(\w+)/', ' <${1}${2}_${3} ', $xmlstr);
$xmlstr = Preg_replace ('/(\w+):(\w+) = "(. *?)" /', ' ${1}_${2}= ' ${3} "', $XMLSTR);
$xmlobj = simplexml_load_string ($XMLSTR);

$json = Json_decode (Json_encode ($xmlobj), true);
Print_r (Json_decode (Json_encode ($xmlobj), true));
Print_r ($json);
$STR = $json [' soapenv_body '] [' checkqyresponse '] [' Ns1_checkqyreturn '];

It's a lot easier to be violent.

 $s =<<< XML!--? XML version= "1.0" encoding= "UTF-8"?--> 
   
    
     
     
       {"Code": "2", "Message": "Enterprise name and Enterprise registration number Match"} 
      
     /soapenv:body> 
   
   XML; $s = preg_replace ('/\w+:/', ' ', $s); $x = simplexml_load_string ($s);p rint_r ($x); 
SimpleXMLElement Object (    [@attributes] = = Array        (            [soapenv] =//schemas.xmlsoap.org/soap/ envelope/            [xsd] =//www.w3.org/2001/XMLSchema            [xsi] =//www.w3.org/2001/XMLSchema-instance        )    [Body] = simplexmlelement Object        (            [Checkqyresponse] = simplexmlelement Object                (                    [Checkqyreturn] + = {"Code": "2", "Message": " (Enterprise name and Enterprise registration number Match "})))        
  • 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.