配列を解析するxmlドキュメントがあります。 どうすればそれらの配列オブジェクトにアクセスして新しい変数に保存できますか? これは、ここで配列オブジェクトを異なる方法で動的にアクセスする方法
<?xml version='1.0'?>
<document>
<txtmsg>
<smstel>1234567</smstel>
<smstxt></smstxt>
<smsdir>Send</smsdir>
<smstime>06/01/2010 7:54:48 am</smstime>
</txtmsg>
<txtmsg>
<smstel>33333333</smstel>
<smstxt>Test sms hhTes12222222</smstxt>
<smsdir>Send</smsdir>
<smstime>06/01/2010 7:54:48 am</smstime>
</txtmsg>
<Contacts>
<conttime>06/01/2010 8:19:05 am</conttime>
<cnt>
<fn>Abc</fn>
<ln>Def</ln>
<cnttel>123456</cnttel>
<cntmtel>3333333</cntmtel>
<cntemail>[email protected]</cntemail>
</cnt>
<cnt>
<fn>def</fn>
<ln>ghi</ln>
<cnttel>234234</cnttel>
<cntmtel>2424</cntmtel>
<cntemail>[email protected]</cntemail>
</cnt>
</Contacts>
</document>
解析されたXMLであり、これは出力される
$contents = file_get_contents('test.xml');
$xml = simplexml_load_string($contents);
print_r($xml);
を解析されたPHPコードの一部です。
SimpleXMLElement Object ([txtmsg] => Array ([0] => SimpleXMLElement Object ([smstel] => 1234567 [smstxt] => SimpleXMLElement Object () [smsdir] => Send [smstime] => 06/01/2010 7:54:48 am) [1] => SimpleXMLElement Object ([smstel] => 33333333 [smstxt] => Test sms hhTes12222222 [smsdir] => Send [smstime] => 06/01/2010 7:54:48 am)) [Contacts] => SimpleXMLElement Object ([conttime] => 06/01/2010 8:19:05 am [cnt] => Array ([0] => SimpleXMLElement Object ([fn] => Abc [ln] => Def [cnttel] => 123456 [cntmtel] => 3333333 [cntemail] => [email protected]) [1] => SimpleXMLElement Object ([fn] => def [ln] => ghi [cnttel] => 234234 [cntmtel] => 2424 [cntemail] => [email protected]))))
どのように私は、個別に、XMLの各要素にアクセスすることができます。.. smstelのような、smstxt、smsdirなど
私は思いますあなたはxpathを見るためにいくつかの時間を費やす必要がありますhttp://www.w3schools.com/xpath/default.asp – CoreCoder
@coreCoderこのような良いリソースを歓迎してくれてありがとう... :) +1 – Natasha
@Natasha beそれを「良いリソース」と呼んでください。http://w3fools.com – Yoshi