0

I have this xml content. I need to get the value from the fullName attribute. I have tried it using lib.xml parser. But it is not working. Could you please help me to achieve this? Thanks in advance.

<?xml version="1.0" encoding="UTF-8"?><currentUserDetails firstName="3rdParty" fullName="3rdParty Access" lastName="Access" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" xmlns=""/>
user2118463
  • 103
  • 3
  • 7

2 Answers2

4

Use simplexml:

$xml = simplexml_load_string($x); // assuming XML in $x
echo $xml['fullName'];

See it working: http://codepad.viper-7.com/7KVHcU

michi
  • 6,565
  • 4
  • 33
  • 56
  • When i assign the $xml['fullName'] to the session variable $_SESSION["fullusername"] = $xml['fullName']; It is displaying as [fullusername] => SimpleXMLElement Object ( [0] => 3rdParty Access ) – user2118463 Apr 26 '13 at 11:07
  • @user2118463: cast to string: `$test = (string)$xml['fullName'];` – michi Apr 26 '13 at 16:23
0
$xmlFile   = "http://www.domaine.com/city.xml";

$data      = simplexml_load_file($xmlFile);

print_r($data);
Yadav Chetan
  • 1,874
  • 2
  • 23
  • 43