SimpleXML:不展开自闭合标签
SimpleXML: do not expand self-closing tags
我在 SimpleXML 中遇到自闭合标签的问题。例如,我的 xml-file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"/>
</root>
PHP代码:
$xml = simplexml_load_file($path);
echo $xml->asXML();
输出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"></b>
</root>
如您所见,SimpleXML 将自闭合标签 <b attr="1"/>
转换为 <b attr="1"></b>
。我不需要这个。如何防止这种转换?
将 XML 的加载方式更改为
$xml = simplexml_load_file($path, null, LIBXML_NOEMPTYTAG);
这给...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"/>
</root>
我在 SimpleXML 中遇到自闭合标签的问题。例如,我的 xml-file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"/>
</root>
PHP代码:
$xml = simplexml_load_file($path);
echo $xml->asXML();
输出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"></b>
</root>
如您所见,SimpleXML 将自闭合标签 <b attr="1"/>
转换为 <b attr="1"></b>
。我不需要这个。如何防止这种转换?
将 XML 的加载方式更改为
$xml = simplexml_load_file($path, null, LIBXML_NOEMPTYTAG);
这给...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a>hello</a>
<b attr="1"/>
</root>