开发者

lookup nodes with xpath in java

Can anybody suggest how can I solve this, there is XML document that I'm trying to append. I'm looking up nodes with xpath, the things is the software which generates this XML sometimes screws it up as following :

<element name="Element ">Element value</element>

So when I'm looking the node up with xpath using //element[@name="Element"] without a blank space I don't get a match. Naturally I get match with this //element[@name="Element "]

Is there something I can do to match this without blank space?Does xpath accept regular expressions or there is more smart way to do t开发者_如何学Gohis, I can change the xml file as well after it has been generated by the sofware(with faulty user input).


(untested).

Would

//element[normalize-space(@name)=="Element"]

work?


A more general (though less accurate) solution could be:

//element[contains(@name,"Element")]

However that would also catch things like name="Elements" and name="Elementary" etc.

can you recommend some useful resources for xpath

Unfortunately there aren't many great such resources in my experience - w3schools is probably your best bet, or the spec itself for more advanced stuff.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜