cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Impactful Individual
Impactful Individual

Parse Xml to get my:myFields and underlying <my:field1> tags issue

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

- https://powerusers.microsoft.com/t5/General-Flow-Discussion/Parse-XML-using-Microsoft-Flow/m-p/11492...

 

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Parse Xml to get my:myFields and underlying <my:field1> tags issue

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,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Highlighted
Community Support
Community Support

Re: Parse Xml to get my:myFields and underlying <my:field1> tags issue

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,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Impactful Individual
Impactful Individual

Re: Parse Xml to get my:myFields and underlying <my:field1> tags issue

Hi @v-bacao-msft 


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!

Highlighted
Community Support
Community Support

Re: Parse Xml to get my:myFields and underlying <my:field1> tags issue

Hi @dimi ,

 

Thank you for your feedback, if there are other alternatives, I would recommend it to you.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Regular Visitor

Re: Parse Xml to get my:myFields and underlying <my:field1> tags issue

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":

replace(replace(replace(variables('XMLContent'),'xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2"',''),'cac:','cac_'),'cbc:','cbc_')

On the compose where I search the XML for the buyer-name with xpath:
xpath(xml(outputs('XMLContentCleaned')),'string(//cac_BuyerCustomerParty/cac_Party/cac_PartyName/cbc_Name)')

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (8,271)