我有一小块希望在 PHP 中解析的 XML。标签没问题,Works
我可以解析所有属性就好了。我遇到的问题是Doesnt
标签,似乎因为它具有我无法访问属性的文本内容。
<Export id="123" apples="pears">
<Works foo="bar" id="234"/>
<Doesnt bar="foo" id="345">Stack Exchange</Doesnt>
</Export>
我运行以下(非常简单的)代码:
$plain = '<Export id="123" apples="pear....esnt></Export>'; // as above
$sxe = simplexml_load_string($plain);
$json = json_encode($sxe);
$native = json_decode($json);
print_r($sxe, true);
print_r($native, true);
我最终得到以下输出:
SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 123
[apples] => pears
)
[Works] => SimpleXMLElement Object
(
[@attributes] => Array
(
[foo] => bar
[id] => 234
)
)
[Doesnt] => Stack Exchange
)
stdClass Object
(
[@attributes] => stdClass Object
(
[id] => 123
[apples] => pears
)
[Works] => stdClass Object
(
[@attributes] => stdClass Object
(
[foo] => bar
[id] => 234
)
)
[Doesnt] => Stack Exchange
)
如您所见,SimpleXMLElement
对象和stdClass
对象都缺少<Doesnt>
标签的所有属性。是否有一些解决方法或替代方法来解决它们?