Recently, when accessing the channel, the interface returned is XML data. Now the interface data return JSON data format is more common.
How to get real data inside XML?
Demo Example:
Create the XML file: Test.xml, the PHP file that is stored in and read under the same level directory.
XML file:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <node>3 <ID>10001</ID>4 <UserName>Admin</UserName>5 <node>6 <token>Secretkey</token>7 </node>8 </node>
PHP Files:
1<?PHP2 $file= ' Test.xml ';3 $xml _object=simplexml_load_file($file);//reads the data from the XML into the array object4 Var_dump($xml _object);5 //All object Result collection6 //object (simplexmlelement) #1 (3) {["id"]=> string (5) "10001" ["UserName"]=> string (5) "admin" ["Node"]=> Object (SimpleXMLElement) #2 (1) {["token"]=> string (9) "Secretkey"}}7 Echo' <pre> ';8 9 Var_dump($xml _object-ID);Ten //$xml _object->id Object Values One //object (simplexmlelement) #2 (1) {[0]=>string (5) "10001"} A Echo' <pre> '; - - Echo($xml _object-ID); the //$xml _object->id Object Values - //10001 (echo cast result) - Echo' <pre> '; - + //note that getting real parameter values in the code requires us to do the cast processing - Var_dump((string)$xml _object-ID); + //$xml _object->id Object Values A //string (5) "10001" at Echo' <pre> '; - - Var_dump((string)$xml _object->node->token); - //$xml _object->node->token Object Values - //string (9) "Secretkey"
Results Print:
PHP reads XML file data