我有这个示例 xml:
<Forms>
<Form Desc="sasld" DocType="1">
<topmostSubform ind="0">
<HouseNo ind="0">413</HouseNo>
<ZipCode ind="0">82051</ZipCode>
<PostOfficeBox ind="0">0</PostOfficeBox>
</topmostSubform>
</Form>
<Form Desc="abcd" DocType="1">
<topmostSubform ind="0">
<TextField1 ind="24" />
<TextField1 ind="25" />
<TextField1 ind="26" />
<DisContActivity-5-0 ind="0" />
<DisWithFranActivity-5-0 ind="0" />
</topmostSubform>
</Form>
<Form Desc="abcd" DocType="5">
<topmostSubform ind="0">
<TextField1 ind="24" />
<TextField1 ind="25" />
</topmostSubform>
</Form>
我想删除所有类型为 Form 且其 DocType 属性值为 1 的节点。
我将此 xml 保存在 Document 对象中。
我试过了:
String xpath_string = "//Form[@DocType ='1']";
XPathExpression xPathExpr = XPATH.compile(xpath_string);
Object result_obj = xPathExpr.evaluate(document,XPathConstants.NODESET);
NodeList nodes = (NodeList) result_obj;
System.out.println(nodes.getLength());
for(int i=1;i<nodes.getLength();i++)
document.removeChild(nodes.item(i));
但它给出了“NOT_FOUND_ERR”。