我正在尝试删除使用 E4X javascript 需要实现的具有空值的 XML 属性。请帮助我。代码:
function xmlparse(xml) {
var children = xml.*, attributes = xml.@*, length = children.length();
for each (var child in children) {
if(child.hasComplexContent())
{
for each (var chi in child.children()) {
var c= chi.localName()
if(chi.hasSimpleContent())
{
if(chi.@value == "")
{
delete chi
}
}
}
var obj = xmlparse(child)
}
}
}
输入:
<Test>
<id value="123"/>
<Book>
<source>
<English>
<bookid value=""/>
<version>
<type>
<place>
<author value="Test123"/>
<index value="10"/>
<display value=""/>
</place>
</type>
</version>
</English>
</source>
</Book>
<Book>
<source>
<German>
<bookid value=""/>
<version>
<type>
<place>
<author value="Test143"/>
<index value=""/>
<display value="Helo"/>
</place>
</type>
</version>
</German>
</source>
</Book>
</Test>
预期输出:
<Test>
<id value="123"/>
<Book>
<source>
<English>
<version>
<type>
<place>
<author value="Test123"/>
<index value="10"/>
</place>
</type>
</version>
</English>
</source>
</Book>
<Book>
<source>
<German>
<version>
<type>
<place>
<author value="Test143"/>
<display value="Helo"/>
</place>
</type>
</version>
</German>
</source>
</Book>
</Test>
通常,我需要从 XML 中删除空标记的值。请指导我,我尝试了一些对我不起作用的示例代码。