How To Parse Xml?

I need to parse some values in xml. The sample values that I need to parse is below:


```php


http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“XML Schema”>

soap:Body





XML Schema” xmlns:msdata=“urn:schemas-microsoft-com:xml-msdata”>



xs:complexType





xs:complexType

xs:sequence





























































































F-4

2342344

dfgdgdfgdsdf

Sender Name

3453453545

Ahmet Taşçı

Teslimat Hazırlık

Alici Subede



Hayır



ÅžiÅŸli

05446546465

Orsan Acente

03120000000

TeslimEdilmedi

2015-01-10T00:00:00+02:00

05.01.2015

ANKARA

Sincan

1

0.00000

0.00000

PÖ/CH

219.00000

8.85000

1

jkshfdfjskdf

Tesellüm

213132

















```





I need to get values of fields between “” and “”.

Exlamle:

2342344

Teslimat Hazırlık







How can I parse this XML?

There are countless ways… Suggest you look at Xpath (or PHP's built-in XML object) for what you want to do. You can also use preg_match and almost anything else that can parse textual data.



Unfortunately there is no standard way to parse XML, just a variety of tools that will provide info in a variety of formats. What I've found works best for php is to extract the elements (or text between beginning and ending tags) and then use:


$xml = simplexml_load_string($your_xml_data);
$json = json_encode($xml);
$php_array - json_decode($json, true);


The above seems to return the most reliable results and is the simplest to implement.

[quote name='tbirnseth' timestamp='1420588322' post='201815']

There are countless ways… Suggest you look at Xpath (or PHP's built-in XML object) for what you want to do. You can also use preg_match and almost anything else that can parse textual data.



Unfortunately there is no standard way to parse XML, just a variety of tools that will provide info in a variety of formats. What I've found works best for php is to extract the elements (or text between beginning and ending tags) and then use:


$xml = simplexml_load_string($your_xml_data);
$json = json_encode($xml);
$php_array - json_decode($json, true);


The above seems to return the most reliable results and is the simplest to implement.

[/quote]

Thanks man. Very helpful.


$doc = new DOMDocument();
$doc->loadXML($response);
echo $doc->getElementsByTagName('status')->item(0)->nodeValue;


This is also good.

Hope this will help you.....XML Reader

Rino