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..
Is there any tool/software to do this in easiest form please suggest.
Converting an XML document to another format
Specify the XML document to be converted in the Input file text field.
Choose the conversion using the Conversion specification combobox.
Specify the output file or directory in the Output file text field.
Greetings,
Maverick
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,
I don't know what I did wrong, but afther a few tests is it working now.
Thanks for you help!!
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:
Please take a try again.
Best Regards,
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
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:
Please take a try.
Best Regards,
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.
Hopefully you can help me with this issue.
Kind regards,
Rob
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:
Flow run history:
Hope it helps.
Best Regards,
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!