, Php parses xml with namespace? The xml file is generated by axis:
{"Code": "2", "message": "The enterprise name matches the enterprise registration number "}
I want to get the content in ns1: checkQyReturn.
How can I obtain it using php?
Reply to discussion (solution)
You can use new SimpleXmlElement to solve this problem.
$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 new SimpleXmlElement to solve this problem.
I tried the namespace, but I couldn't parse the converted json.
$ 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 much simpler to be violent.
$ S = <XML
{"Code": "2", "message": "The enterprise name matches the enterprise registration number "}
XML; $ s = preg_replace ('/\ w +:/', ', $ s); $ x = simplexml_load_string ($ s); print_r ($ x );
SimpleXMLElement Object ([@ attributes] => Array ([soapenv] => // define [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 "})))