0

I cannot able to read node.I want to read the USER_ID node value.When i am trying to read with simplexml_load_string.

I am unable to read the node value.

This is my xml code :

<?xml version="1.0" encoding="utf-16" standalone="yes"?> 
<RESULT>      
<SUCCESS>1</SUCCESS> 
<ERRMESSAGE /> 
<REMARKS /> 
<DATA>
  <data>
    <USERS>
      <U> 
        <USER_ID>1</USER_ID>
      </U>
  </data>
</DATA>
</RESULT>
manoj
  • 41
  • 2
  • 10
  • So which node value are you trying to read, and how are you trying to read it? – Mark Baker Feb 03 '16 at 10:29
  • 1
    The XML is invalid, the `U` element is not closed. – ThW Feb 03 '16 at 10:29
  • I am just trying to read by using $xml=simplexml_load_string($body);The result is showing like: SimpleXMLElement Object ( [0] => 1 ) – manoj Feb 03 '16 at 10:40
  • U element is closed.But i am not able to read. – manoj Feb 03 '16 at 10:46
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – michi Feb 03 '16 at 12:30

1 Answers1

0

Your xml file is not valid. Change encoding of xml document to utf-8. Then just access like normal object:

$xmlfile = file_get_contents('test.xml');
$array = simplexml_load_string($xmlfile);

echo "<pre>";
print_r($arr->DATA->data->USERS->U->USER_ID);
echo "</pre>";
Kārlis Millers
  • 664
  • 2
  • 11
  • 29