hotmeatballsoup
hotmeatballsoup

Reputation: 605

Wildcard XPath nested element selection by example

I am being given XML that looks like this:

<?xml version='1.0' encoding='UTF-8'?>
<singleton-list>
    <fizzbuzz>
        <amountId>123</amountId>
        <countryId>456</countryId>
        <action>Overwrite</action>
    </fizzbuzz>
</singleton-list>

However, the outer-most element (in this case, singleton-list) will be different each time, and will be one of many different values. For instance I might get another XML message that looks like this:

<?xml version='1.0' encoding='UTF-8'?>
<aggregateList>
    <fizzbuzz>
        <amountId>123</amountId>
        <countryId>456</countryId>
        <action>Overwrite</action>
    </fizzbuzz>
</aggregateList>

I'm trying to write an XPath that selects the fizzbuzz out of each message I receive, regardless of what the outer-most element is (singleton-list, aggregateList, or otherwise).

I think I could do something involving a wildcard, but I'm not sure if asterisks have special meaning in XPath or if I'm going about this the wrong way.

My best attempt at an XPath to do this selection is:

/*/fizzbuzz

Is this correct or is there a better way to do this?

Upvotes: 1

Views: 159

Answers (1)

supputuri
supputuri

Reputation: 14135

either you can use //fizzbuzz or /*/fizzbuzz.

Upvotes: 2

Related Questions