我正在使用simplexml_load_file
使用var_dump
打开的plist打开plist,但是我不确定实际访问项目的语法。我需要得到的只是2条信息。
simplexml_load_file中的var_dump如下所示。我想要的只是文字“SimpleCalculator”
object(SimpleXMLElement)#1 (2) {
["@attributes"]=>
array(1) {
["version"]=>
string(3) "3.0"
}
["dict"]=>
object(SimpleXMLElement)#2 (2) {
["key"]=>
string(5) "items"
["array"]=>
object(SimpleXMLElement)#3 (1) {
["dict"]=>
object(SimpleXMLElement)#4 (3) {
["key"]=>
array(2) {
[0]=>
string(6) "assets"
[1]=>
string(8) "metadata"
}
["array"]=>
object(SimpleXMLElement)#5 (1) {
["dict"]=>
object(SimpleXMLElement)#7 (2) {
["key"]=>
array(2) {
[0]=>
string(4) "kind"
[1]=>
string(3) "url"
}
["string"]=>
array(2) {
[0]=>
string(16) "software-package"
[1]=>
string(7) "__URL__"
}
}
}
["dict"]=>
object(SimpleXMLElement)#6 (2) {
["key"]=>
array(5) {
[0]=>
string(17) "bundle-identifier"
[1]=>
string(14) "bundle-version"
[2]=>
string(4) "kind"
[3]=>
string(5) "title"
[4]=>
string(8) "subtitle"
}
["string"]=>
array(5) {
[0]=>
string(16) "SimpleCalculator"
[1]=>
string(3) "000"
[2]=>
string(8) "software"
[3]=>
string(33) "com.mywork.demo"
[4]=>
string(3) "1.0"
}
}
}
}
}
}
XML看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="3.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>__URL__</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>SimpleCalculator</string>
<key>bundle-version</key>
<string>000</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>com.mywork.demo</string>
<key>subtitle</key>
<string>1.0</string>
</dict>
</dict>
</array>
</dict>
</plist>
答案 0 :(得分:2)
<强> Tested and Works.
强>
<?php
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
echo $xml->dict->array->dict->dict->string;//Simple Calculator
} else {
exit('Failed to open test.xml.');
}
编辑:
你需要像这样循环
echo $xml->dict->array->dict->dict->string[0];//Simple Calculator
echo $xml->dict->array->dict->dict->string[1];//000
echo $xml->dict->array->dict->dict->string[2];//software