我希望使用php存储domorder下的所有值,就像下面的数组变量一样,在xml文件中有时$ tld [veribal] [$ i]可能有多个值 注意:xml文件来自url
$tld[0] = dombiz;
$tld[dombiz][0] = biz;
$tld[1] = dominfo;
$tld[dominfo][0] = info;
xml文件:
<hashtable>
<entry>
<string>domorder</string>
<map-array>
<map>
<entry>
<string>dombiz</string>
<vector>
<string>biz</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>dominfo</string>
<vector>
<string>info</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domcno</string>
<vector>
<string>com</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domorg</string>
<vector>
<string>org</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domus</string>
<vector>
<string>us</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>donutsgroup2</string>
<vector>
<string>fish</string>
<string>chat</string>
<string>associates</string>
<string>media</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>dotlove</string>
<vector>
<string>love</string>
</vector>
</entry>
</map>
</map-array>
</entry>
<entry>
<string>digicert</string>
<string-array/>
</entry>
</hashtable>
答案 0 :(得分:0)
此代码仅打印dombiz
和biz
,但您可以进行迭代。
$myXMLData = "<hashtable>
<entry>
<string>domorder</string>
<map-array>
<map>
<entry>
<string>dombiz</string>
<vector>
<string>biz</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>dominfo</string>
<vector>
<string>info</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domcno</string>
<vector>
<string>com</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domorg</string>
<vector>
<string>org</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>domus</string>
<vector>
<string>us</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>donutsgroup2</string>
<vector>
<string>fish</string>
<string>chat</string>
<string>associates</string>
<string>media</string>
</vector>
</entry>
</map>
<map>
<entry>
<string>dotlove</string>
<vector>
<string>love</string>
</vector>
</entry>
</map>
</map-array>
</entry>
<entry>
<string>digicert</string>
<string-array/>
</entry>
</hashtable>";
$xml = simplexml_load_string($myXMLData);
$json = json_encode($xml);
$tld = json_decode($json,TRUE);
print($tld['entry'][0]['map-array']['map'][0]['entry']['string']); // dombiz
print('<br />');
print($tld['entry'][0]['map-array']['map'][0]['entry']['vector']['string']); // biz