cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Community Support
Community Support

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
Community Support
Community Support

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

Impactful Individual
Impactful Individual

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!

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.
Regular Visitor

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
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (2,028)