1

I have this piece of code:

<?xml version="1.0"?><testXML><UserId>00077</UserId><FirstName><![CDATA[ Test]]></FirstName><LastName><![CDATA[Test]]></LastName></testXML>

obtained by using urldecode($info).

How I can parse this information?

Can I use simplexml_load_file (urldecode($info))?

MMM
  • 7,221
  • 2
  • 24
  • 42
user880386
  • 2,737
  • 7
  • 33
  • 41

1 Answers1

3

Make use of simplexml_load_string in PHP

<?php
$xml='<?xml version="1.0"?><testXML><UserId>00077</UserId><FirstName><![CDATA[ Test]]></FirstName><LastName><![CDATA[Test]]></LastName></testXML>';
$xml = simplexml_load_string($xml);
print_r($xml);

OUTPUT :

SimpleXMLElement Object
(
    [UserId] => 00077
    [FirstName] => SimpleXMLElement Object
        (
        )

    [LastName] => SimpleXMLElement Object
        (
        )

)

If you want to access specific element.. you can do like echo $xml->UserId; that prints you 00077 , Also, you can make use of a foreach construct to traverse through all the elements

A foreach demo

foreach($xml as $k=>$v)
{
    echo "$k => $v\n";
}

OUTPUT :

UserId => 00077
FirstName =>  Test
LastName => Test
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126