XML : XQuery: Querying all instances of a certain tag?

I am querying an xml document that has changed structure, previously there was only one tag but this has changed to have multiple.

How can I return all the "id" values in the attribute tags?

XML:

  <Products>          <Product>              <name>Sample name</name>              <attribute id="sampleid1" location="sampleLocation1" type="sampleType1"/>              <attribute id="sampleid2" location="sampleLocation2" type="sampleType2"/>          </product>      </Products>     

Current Query (will only return the id of one Attribute):

  format("//Products/Product[name='%s']/attribute/@id/string()"    

The query shown above would return e.g. "sampleId1" when there was only one attribute.

Now that there are more than one attributes how can I query for all attribute Ids, i.e. in this case to return "sampleId1" and "sampleId2" ?

No comments:

Post a Comment