Reputation: 762
I am working in a logic app that retrieve values from an XML. I was working initially with this XML structure:
<Parent>
<Child1>Hello</Child1>
<Child2>World</Child2>
</Parent>
And I was able to retrieve the values by using this XPath expression (this is inside of a For_Each action):
"@{xpath(xml(items('For_each_node')), 'string(/*[local-name()=\"Parent\"]/*[local-name()=\"Child1\"])')}"
It works great and I get 'Hello' in this example, however I've been given now this XML:
<Parent>
<Child N="1">Hello</Child>
<Child N="2">World</Child>
</Parent>
And now the expression placed above retrieves nothing. I think I need to adjust the expression to do something like 'retrieve node value where child attribute equals 1' but I am not able to make it work, I've seen examples on how to do that but somehow the syntax used in Logic apps for XPath is kind of different as how 'standard' XPath is used.
I would appreciate your help, thanks!
Upvotes: 1
Views: 6915
Reputation: 66723
The XPath to select elements that have an N
attribute with the value of 1
and a local-name()
of Child
/*[local-name() = "Parent"]/*[local-name() = "Child" and @N = "1"]
Applied to the code you had originally provided:
"@{xpath(xml(items('For_each_node')), 'string(/*[local-name()=\"Parent\"]/*[local-name()=\"Child\" and @N=\"1\"])')}"
If your XML isn't bound to a namespace, then you can simplify things further. Instead of matching generically on any element with *
and then using a predicate to test the local-name()
, just use:
/parent/child[@N="1"]
Upvotes: 1