当加载一个xml文档并使用转换为数组时
json_decode(json_encode(simplexml_load_string($xml)), 1);
所有空的 xml 节点 ( <node />
) 都被转换为 array() 我希望它们是一个空字符串。我是否需要遍历所有元素并将每个空节点替换为其他内容?
我正在使用 $xml = new SimpleXmlElement($this->feed_uri, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG , true);
加载 xml 文档
最佳答案
您无法自动完成该操作。因此,您需要在转换后将空数组替换为空字符串。
顺便说一句,LIBXML_NOEMPTYTAG
在这里没有意义:
This option is currently just available in the DOMDocument::save and DOMDocument::saveXML functions. http://ua1.php.net/manual/en/libxml.constants.php
关于php - simplexmlelement 上的 json_decode/encode 添加数组而不是空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13865308/