English 中文(简体)
具体职位从xml中删除
原标题:deleting node from xml at specific position

我的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>

我现在要删除选定的行文。 Sayuser已经选定了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)
最佳回答

令人痛心的Guys问题是,表达形式缺失。 因此,我犯了错误。 我道歉。

问题回答

为什么使用这种复杂的XPath? 引言

String expression = "//b[.=14]";

or, if you must check the correct hierarchy, this one:

String expression = "/As/a/Bs/b[.=14]";




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签