1

The question is quite silly, but I am completely stuck. I want to extract child nodes of a node based on a condition. The XML is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<products xmlns="http://xml.netbeans.org/schema/products">
    <product>
        <productID>1</productID>
        <picture>1000</picture>
        <productName>abc</productName>
        <price>400</price>
    </product>
    <product>
        <productID>2</productID>
        <picture>2000</picture>
        <productName>bcd</productName>
        <price>275</price>
    </product>
</products>

I want to use local-name() with contains.

My expression is: //*[local-name()='products' and contains(productName,'a')]

But not working.

Has anyone any idea of what I should do?

2 Answers 2

1

I assume you want to get the product tag, so this could help:

'//*[local-name()="products"]/*[local-name()="product" and contains(./*[local-name()="productName"], "a")]'
Sign up to request clarification or add additional context in comments.

Comments

0

I want to use local-name() with contains.

This XPath,

//*[local-name()='productName' and contains(., 'a')]/..

uses local-name() and contains() to select all parent elements of those productName elements whose string value contains an 'a', as requested.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.