Hi all!
I am having issues parsing an Xml file, I have looked at:
- https://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
- https://powerusers.microsoft.com/t5/Building-Flows/Iterate-XML-with-flow/m-p/163734#M16546
But i can't seem to find something to get this sort of tag (which according to me comes from InfoPath)
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-01-31T13:38:00" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="nl-BE"> <my:field1></my:field1> <my:field2></my:field2> </my:myFields>
Where i would like to be able to iterate over everything that is inbetween the "my:myFields" tags.
I get the error:
InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2562': 'The template language function 'xpath' parameters are invalid: the 'xpath' parameter must be a supported, well formed XPath expression. Please see https://aka.ms/logicexpressions#xpath for usage details.'.
when trying to get it like this:
xpath(xml(outputs('Compose_File_content')),'string(my:myFields)') xpath(xml(outputs('Compose_File_content')),'string(/my:myFields)') xpath(xml(outputs('Compose_File_content')),'string(//my:myFields)') xpath(xml(outputs('Compose_File_content')),string('my:myFields')) xpath(xml(outputs('Compose_File_content')),string('/my:myFields')) xpath(xml(outputs('Compose_File_content')),string('//my:myFields')) UPDATE: tried this as well xpath(xml(outputs('Compose_File_content')),string('//myFields')) xpath(xml(outputs('Compose_File_content')),string('/myFields')) xpath(xml(outputs('Compose_File_content')),string('//field1')) xpath(xml(outputs('Compose_File_content')),string('/field1')) xpath(xml(outputs('Compose_File_content')),string('//myFields/field1')) xpath(xml(outputs('Compose_File_content')),string('/myFields/field1')) xpath(xml(outputs('Compose_File_content')),string('*/*')) xpath(xml(outputs('Compose_File_content')),string('@*')) xpath(xml(outputs('Compose_File_content')),string('*my:myFields')) xpath(xml(outputs('Compose_File_content')),string('./my:myFields')) xpath(xml(outputs('Compose_File_content')),string('my:*')) ... maybe even others i forgot
However I am able to fetch all content that is between any tag (all in one blob) but that's the only thing I am able to grab at this time and is not what I want of course.
using this I am able to grab all content:
xpath(xml(outputs('Compose_File_content')),string('.'))
Can anyone advise me how i can get the value in the tags of
my:field1
my:field2
and so on, iterating over them would be preferred.
Thank you in advance!
Solved! Go to Solution.
Hi @dimi ,
I tested it on my side using the xml data you provided. The problem seems to be related to adding xmlns.
I removed my: and then used Expression below to get the value of field1.
<myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-01-31T13:38:00" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="nl-BE"> <field1>1</field1> <field2>2</field2> </myFields>
xpath(xml(outputs('Compose')),'string(/myFields/field1)')
Xml can perform XPath queries, but it seems that XPath queries are limited to XML without a namespace (no xmlns). Once an XML with a namespace is encountered, the corresponding XPath query may have no results.
Best Regards,
Hi @dimi ,
I tested it on my side using the xml data you provided. The problem seems to be related to adding xmlns.
I removed my: and then used Expression below to get the value of field1.
<myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-01-31T13:38:00" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="nl-BE"> <field1>1</field1> <field2>2</field2> </myFields>
xpath(xml(outputs('Compose')),'string(/myFields/field1)')
Xml can perform XPath queries, but it seems that XPath queries are limited to XML without a namespace (no xmlns). Once an XML with a namespace is encountered, the corresponding XPath query may have no results.
Best Regards,
Thank you so much for testing that out and for the explanation!
I have created an idea here where you can vote for it.
Thank you for your feedback!
Hi @dimi ,
Thank you for your feedback, if there are other alternatives, I would recommend it to you.
Best Regards,
While we are waiting for custom-tags and namespace-specification to work for xpath in Flow I made a workaround that seems to work for me:
I added a Compose before I use xpath where i "clean" the XML and replace strings for the tags that aren't working. In this case a Peppol-bis-order XML-file where the tags cac:... and cbc:... are common. I replaced the : with _ and use that later on in the xpath-commands
On the compose named "XMLContentCleaned":
I found a solution using local-name() to perform the XPath query in this post.
https://powerusers.microsoft.com/t5/Building-Flows/Using-xPath-on-an-HTTP-xml-body/td-p/73531