Get node content from xml file and transform it into php array?
Posted
by Kirzilla
on Stack Overflow
See other posts from Stack Overflow
or by Kirzilla
Published on 2010-04-18T11:45:00Z
Indexed on
2010/04/18
11:53 UTC
Read the original article
Hit count: 327
Hello,
I'm looking for solution to extract some node from large xml file (using xmlstarlet http://xmlstar.sourceforge.net/) and then parse this node to php array.
elements.xml
<?xml version="1.0"?>
<elements>
<element id="1" par1="val1_1" par2="val1_2" par3="val1_3">
<title>element 1 title</title>
<description>element 1 description</description>
</element>
<element id="2" par1="val2_1" par2="val2_2" par3="val2_3">
<title>element 2 title</title>
<description>element 2 description</description>
</element>
</elements>
To extract element tag with id="1" using xmlstarlet I'm executing this shell command...
xmlstarlet sel -t -c "/elements/element[id=1]" elements.xml
This shell command outputs something like this...
<element id="1" par1="val1_1" par2="val1_2" par3="val1_3">
<title>element 1 title</title>
<description>element 1 description</description>
</element>
How could I parse this shell output into php array?
Thank you.
© Stack Overflow or respective owner