大きなxmlファイルから( xmlstarlet http://xmlstar.sourceforge.net/を使用して)ノードを抽出し、このノードをphp配列に解析するソリューションを探しています。
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>
xmlstarletを使用してid="1"の要素タグを抽出するには、このシェルコマンドを実行しています...
xmlstarlet sel -t -c "/elements/element[id=1]" elements.xml
このシェルコマンドは次のようなものを出力します...
<element id="1" par1="val1_1" par2="val1_2" par3="val1_3">
<title>element 1 title</title>
<description>element 1 description</description>
</element>
このシェル出力をphp配列に解析するにはどうすればよいですか?
ありがとうございました。
http://php.net/manual/en/function.simplexml-load-string.phpは非常に便利です。このSimpleXML関数は、抽出されたXMLをSimpleXMLオブジェクトに変換します。