• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to parse xml

#1
Hi guys, I have xml as string.

I can't take "value". Can you help me?

Example xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<SYSMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ext="xxxxxxxwebsite">
<messageType code="1" value="SYS Test Cevabı" codeSystemGuid="0a9ba485-e7e0-4abb-9c86-0a14fd364bb8" version="1" />
<documentGenerationTime value="201512041717" />
<author>
<healthcareProvider code="0" value="SYS" codeSystemGuid="c9dbe1cb-57cb-48fb-bdd3-d622e0e304c6" version="1" />
</author>
<recordData>
<KayitCevabi>
<sonucKodu value="E2003"/>
<sonucMesaji value="SYSTakipNo geçerli değil"/></KayitCevabi>
</recordData>
</SYSMessage>

I need value of "sonucKodu" I mean "E2003".

I didn't handle. I used this code for taking value.
Code:
$dom = new DOMDocument();
           $dom->loadlXML($xml);
           $img = $dom->getElementsByTagName('sonucMesaji')->item(0);
           echo $img->attributes->getNamedItem("value")->value;
Reply

#2
You could use SimpleXML...
Code:
$doc = simplexml_load_string($xml);
echo $doc->recordData->KayitCevabi->sonucMesaji["value"];
James Parry
Project Lead
Reply

#3
You could try this:

PHP Code:
$dom = new DOMDocument();
$dom->loadXML($xml);
$img $dom->getElementsByTagName('sonucKodu')->item(0);
echo 
$img->getAttribute('value'); 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.