cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

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

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
Highlighted
Super User II
Super User II

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!

Highlighted
Community Support
Community Support

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.
Highlighted
New Member

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

 

Highlighted
Community Support
Community Support

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.
Highlighted
New Member

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

 

Highlighted
Community Support
Community Support

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

Highlighted
New Member

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

Highlighted
Community Support
Community Support

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

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Users online (6,722)