我有如下 XML:
<As>
<a>
<Bs>
<b>5</b>
<Bs>
</a>
<a>
<Bs>
<b>9</b>
<Bs>
</a>
<a></a>
<a>
<Bs>
<b>12</b>
<b>14</b>
<b>15</b>
</Bs>
</a>
现在我想删除节点选择的行。假设用户选择了 node <b>14</b>
。
我生成的表达式为:
String expression = "/As/a[4]/Bs/b[2]";
Node node = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE);
node.getParentNode().removeChild(node);
它给出以下异常:
javax.xml.transform.TransformerException: Extra illegal tokens: 'health-history-questions', '/', 'health-history-question', '[', '3', ']'
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:145)
at org.apache.xpath.XPath.<init>(XPath.java:178)
at org.apache.xpath.XPath.<init>(XPath.java:266)
at org.apache.xpath.jaxp.XPathImpl.eval(XPathImpl.java:195)
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:281)