, Php parses xml with namespace?

Source: Internet
Author: User
, 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 "})))

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.