1

I have the following xml:

<Products>
    <Product>
        <name>Sample name</name>
        <attribute id="sampleid" location="sampleLocation" type="sampleType"/>
        <price>12345</price> 
    </product>
</Products> 

How can I return the following data from this XML for a given name (always unique):

1. location (e.g. "sampleLocation")
2. type (e.g. "sampleType")
3. price (e.g. 12345

I currently am able to query each individually to return values, but im not sure of the syntax to return multiple values together.

Example of individual query for location:

 ResourceSet resourceSet = service.query(
                        format("//Products/Product[name='%s']" +
                                        "/attribute/@Location/string()"
                                , StringEscapeUtils.escapeXml(journey_Name)
                        ));

The query above will return: "sampleLocation".

1
  • 1
    What XQuery processor and what API are you using? Commented Oct 13, 2016 at 15:59

1 Answer 1

1

The following query returns a sequence of three strings:

/Products/Product/(string(attribute/@location), string(attribute/@type), string(price)) 

How to return a sequence of three strings to your Java app depends on the XQuery processor and API that you are using, which you haven't told us.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.