Reputation: 4767
Let's say I have the following XML:
<Data xmlns:R="Rows" xmlns:C="Columns" xmlns:V="Values">
<R:ProductGroup value="Electronics">
<R:Product value="Computer">
<C:Year value="2018">
<V:SumOfRevenue value="104" />
<V:SumOfUnits value="3" />
</C:Year>
<C:Year value="2019">
<V:SumOfRevenue value="82" />
<V:SumOfUnits value="9" />
</C:Year>
<C:Year value="(all)">
<V:SumOfRevenue value="186" />
<V:SumOfUnits value="12" />
</C:Year>
</R:Product>
</R:ProductGroup>
</Data>
The data is separated into Rows
and Columns
. And so I can target a Row Element by doing something like //R:Name
and a column with //C:Name
. Is it possible to use a third namespace (or whatever it would be called) to target both. For example, something like A:
(standing for "All") that could target either a column or a row? Or, is it even possible to 'skip' the namespace evaluation (perhaps something like local-name(...)
) to do what I'm trying to accomplish?
Upvotes: 0
Views: 51
Reputation: 4472
Yes, that's possible using local-name()
function. Here is an example of XPath expression which will return value "9":
//*[local-name()='Product'][@value='Computer']/*[local-name()='Year'][@value='2019']/*[local-name()='SumOfUnits']/@value
Upvotes: 1