cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
rob3
Level: Powered On

XML convert to other XML format

Hi,

 

I want to transform XML data to another XML format, I receive it by e-mail. 

In Flow I created receive from mail, that works well, from a simple XML I get a xml value with xpath. 

 

But from the XML below I cannot get the UniqueCreatorIdentification value.

I use this code:

xpath(xml(body('Bijlage_ophalen')), 'string(/pay:invoice/invoiceIdentification/uniqueCreatorIdentification)')

 

What is wrong with this code?
Is this te best way to transform a XML to another format XML or is there a better way?

I want to use compose to put the values from the original file into the new file and save the file in the new format XML and store it with FTP.

 

Kind regards,

Rob

<?xml version="1.0" encoding="UTF-8" ?>
<pay:invoice xmlns:pay="urn:ean.ucc:pay:2" xmlns:eanucc="urn:ean.ucc:2" xmlns:px="urn:ean.ucc:pay:vat:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ean.ucc:pay:2 Factuur_bou002.xsd" creationDateTime="" documentStatus="ORIGINAL">
documentStructureVersion>
  <versionIdentification>002</versionIdentification>
  </documentStructureVersion>
<invoiceIdentification>
  <uniqueCreatorIdentification>452823</uniqueCreatorIdentification>
<contentOwner>
  <gln>8714xxxxxxxxxx</gln>
  </contentOwner>
  </invoiceIdentification>
<invoiceCurrency>
  <currencyISOCode>EUR</currencyISOCode>
  </invoiceCurrency>
  <invoiceType>INVOICE</invoiceType>
<shipTo>
  <gln>0000000000000</gln>
  </shipTo>
.. and further..
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: XML convert to other XML format

Hi @rob3 ,

 

Could you share all the details of your configuration?

This is not a problem with base64ToString() function. It is clear in the Flow run history that ContentBytes is null.

So the first parameter passed to the base64ToString() function is null.

Please ensure that Include Attachments field value is Yes.

Image reference:

43.PNG

Please take a try again.

 

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

8 REPLIES 8
Super User
Super User

Re: XML convert to other XML format

First, I'd recommend reviewing the official Data Operations documentation and the Trigger a Flow with Email documentation as a refresher. The Microsoft Flow Community post, Modify Dynamic Content Before Use in Flow may help as well.

You should be able to perform the conversion you're seeking using Flow's Logical Expressions and Functions. If you provide a detailed and expanded screenshot of your Flow, as well as the error messages you receive while saving or running your Flow, we may be able to assist further.

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. THANKS!

Community Support Team
Community Support Team

Re: XML convert to other XML format

Hi @rob3 ,

 

I tested it on my side using the xml data you provided. The problem seems to be related to adding xmlns.

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.

 

What I can do for you is remove pay: so that we can use xpath() function to get the value of the specified element. This may be contrary to your intention, but this is a practice that can be considered.

I tested it with the XML you provided. It seems that there is an escape character, and documentStructureVersion is missing "<". After modification, the value of the specified element is obtained by the following method.

 

Expression:

replace(outputs('Compose'),'pay:','')
xpath(xml(outputs('Compose_2')),'string(/invoice/invoiceIdentification/uniqueCreatorIdentification)')

Image reference:

6.PNG

Flow run history:

7.PNG

Hope it helps.

 

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.
rob3
Level: Powered On

Re: XML convert to other XML format

Hi Barry,

 

Thanks for your reply!

If I do the same as you it works, but when I receive a XML file by e-mail I get an error.

The error is:

 

InvalidTemplate. Unable to process template language expressions in action 'Replace' inputs at line '1' and column '2594': 'The template language function 'replace' expects its first parameter 'string' to be a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#replace for usage details.'.

 

I receive the e-mail, get the attachement, put the body of the attachement in a compose, then I use the replace function.

Printscreen

Printscreen

 

Hopefully you can help me with this issue.


Kind regards,

Rob

 

Community Support Team
Community Support Team

Re: XML convert to other XML format

Hi @rob3 ,

 

Please try using base64ToString() function to convert the Attachment content to a String value, then using replace() function.

 

Expression reference:

base64ToString(item()['ContentBytes'])

Image reference:

33.PNG

34.PNG

Please take a try.

 

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.
rob3
Level: Powered On

Re: XML convert to other XML format

Hi Barry,


Thanks for your reply!

 

Unfortunately I get an error:

InvalidTemplate. Unable to process template language expressions in action 'Compose_2' inputs at line '1' and column '2594': 'The template language function 'base64ToString' expects its parameter to be a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#base64ToString for usage details.'.

 

See the: Printscreen

Seems it has the XML file, but the transform with the base64tostring isn't working.

 

Kind regards,

Rob

 

Community Support Team
Community Support Team

Re: XML convert to other XML format

Hi @rob3 ,

 

Could you share all the details of your configuration?

This is not a problem with base64ToString() function. It is clear in the Flow run history that ContentBytes is null.

So the first parameter passed to the base64ToString() function is null.

Please ensure that Include Attachments field value is Yes.

Image reference:

43.PNG

Please take a try again.

 

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

rob3
Level: Powered On

Re: XML convert to other XML format

I don't  know what I did wrong, but afther a few tests is it working now.

Thanks for you help!!

Community Support Team
Community Support Team

Re: XML convert to other XML format

Hi @rob3 ,

 

Thank for your feedback.

And if your problem has been resolved, please click “Accept as Solution” and mark the post as solved, so that more users can see a similar resolution.

 

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.

Helpful resources

Announcements
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!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (4,336)