I have following XML:
<Library> <Item> <Field Name="Name">smooth</Field> <Field Name="File Type">mid</Field> <Field Name="File Size">60026</Field> </Item> <Item> <Field Name="Name">mid</Field> <Field Name="File Type">mp3</Field> <Field Name="File Size">4584972</Field> </Item> </Library>
I'd like to get all item names of items of the file type "mid". My XPATH query looks as
/Library/Item/Field [ @Name="Name" and (../Field[@Name="File Type" and ../Field[.="mid"]]) ]
But unfortunately both items are returned from that query.
smooth mid
Seems that the last condition is not checked against fields with the attribute "File Type" only, but all fields. Which results in a return of the name "mid", even if this item is of file type "mp3".
How can I restrict the comparison with "mid" to the value of the field with the attribute Name="File Type"?
Can anybody suggest me an XPATH syntax which works as expected?
Filtering with XPath First, add your filtering rules by specifying the rule criteria and clicking the Add Rule button. Then click Apply Filters to XPath to generate an XPath expression. You can also manually write an XPath expression to filter your file.
XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.
XPath predicates can be applied anywhere, this would be more straight-forward:
/Library/Item[Field[@Name="File Type"] = "mid"]/Field[@Name="Name"]
Your own expression would be correct as
/Library/Item/Field[ @Name="Name" and ../Field[@Name="File Type"] = "mid" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With