I am looking for an XPATH expression that will perform a search to ensure a field does not have a letter in it. For example input XML:
<?xml version="1.0" encoding="UTF-8"?>
<payload>
<records>
<record>
<number>123</number>
</record>
<record>
<number>456</number>
</record>
<record>
<number>78A</number>
</record>
</records>
</payload>
I want it too filter out the third result as it has a letter in the tag. So return this:
<?xml version="1.0" encoding="UTF-8"?>
<payload>
<records>
<record>
<number>123</number>
</record>
<record>
<number>456</number>
</record>
</records>
</payload>
Is that possible to do in a simple XPATH?
So something like /payload/records/record[reg expression here?]
@Cylian
This is what i mean:
<?xml version="1.0" encoding="UTF-8"?>
<payload>
<records>
<record>
<number>123</number>
<time>12pm</time>
<zome>UK</zome>
</record>
<record>
<number>456</number>
<time>12pm</time>
<zome>UK</zome>
</record>
<record>
<number>78A</number>
<time>12pm</time>
<zome>UK</zome>
</record>
</records>
</payload>
You can easily delete the nodes using an XQuery Update expression, too:
XPath (both 1.0 and 2.0) is a query language for XML documents.
As such an XPath expression only selects sets of nodes (or extracts other data), but cannot alter the structure (like delete a node) of the XML document.
Therefore, it is not possible to construct an XPath expression that alters the provided XML document to the wanted one.
This task can easily be accomplished with XSLT or XQuery (not so easily):
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
Try this(XPath 2.0):