【发布时间】:2015-07-14 18:06:26
【问题描述】:
我有一个包含以下内容的 xml。
<build id="1.2.3" name="Build 1.2.3" master="Ghost">
<features>
<module id="glob" name="Global Module"></module>
<module id="sis" name="Instrumented System Module"></module> <!-- placed here for ordering with instance-specific tasks -->
<module id="tracker" name="Action Item Tracker Module"></module> <!-- placed here for ordering with instance-specific tasks -->
<!-- placed here for ordering with instance-specific tasks -->
</features>
<fixes>
<module id="sis" name="Instrumented System Module"></module> <!-- placed here for ordering with instance-specific tasks -->
<module id="omi" name="Operate/Maintain Module">
<description id="879">Eric is testing this thing to make sure it works</description>
</module>
<module id="fsa" name="Functional Safety Assessments Module"></module> <!-- placed here for ordering with instance-specific tasks -->
<module id="personnel" name="Personnel Module"></module> <!-- placed here for ordering with instance-specific tasks -->
<module id="general" name="General">
<description id="879">Bug Fixed Delete and Cascade</description>
</module>
</fixes>
</build>
所有模块的 in features 元素都是空的。
如果这些元素是空的,我会尽量不显示它们,有人能指出我正确的方向吗?
这是我尝试过的。
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadXML($master_build_info_sorted_old);
$xpath = new DOMXPath($doc);
foreach ($xpath->query('//*[not(node())]') as $node) {
$node->$inst_child->module->removeChild($node);
}
$doc->formatOutput = true;
$doc->saveXML();
但这不起作用,元素仍然显示。我是 simplexml 的新手,非常感谢任何帮助。
【问题讨论】:
-
这不是 simplexml,就像在你的标题和标签中一样