Reputation: 2485
I have an XML file which contains some Nodes that needs to be varied at runtime. For example:
<pt:Type>#type</pt:Type>
<pt:Value>#value</pt:Value>
I'd like to scan the XML file and search for Nodes which have a "#" pattern in it. My purpose is to fill up the XML using some data I have in memory. Which is the fastest way to do it in Java ? Maybe is there an XPath expression to gather all nodes having a certain value ?
Upvotes: 1
Views: 194
Reputation: 21
my suggestion is to go with XQuery pattern matching in java way something like this
XQExpression xqe = xqc.createExpression();
xqe.executeQuery("doc('orders.xml')//order[id='174']");
Upvotes: 1
Reputation: 16354
You can use an XPath query with the contains
criteria function which would return elements that which values holds the set of character provided. It should be something like the following:
//*[contains(text(), '#')]
Upvotes: 1
Reputation: 19492
Xpath
Any node where the first text child node equals '#type':
//*[text() = '#type']
Any node where the first text child node starts with '#':
//*[starts-with(text(), '#')]
Any node where the first text child node starts with '#' after normalizing spaces:
//*[starts-with(normalize-space(text()), '#')]
Upvotes: 1