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 "})))