Logic Apps cannot extract value from XML file
Question
Wednesday, June 13, 2018 3:36 PM
I'm trying to extract data from an XML with Xpath.
xpath(xml(body('XML_Validation')), '/Document/CustCustomerGroupEntity/PAYMENTTERMID')
But I get the error:, when I try to email that value as a test.
Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2797': 'The template language function 'xml' expects its parameter to be a string or an object. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#xml for usage details.'.
The XML is coming from the service bus and I just did a XML Validate after the trigger action.
What's wrong in my syntax?
All replies (5)
Wednesday, June 13, 2018 8:13 PM âś…Answered
Hi fredrik,
Try it like below, it will work. you can change the XPath Expression inside the string
@{xpath(xml(base64ToBinary(triggerBody()?['ContentData'])),'string(/bookstore/book/author)')}
Sujith
Wednesday, June 13, 2018 5:26 PM
Hi,
Body('XML_Validation) will not return anything.it will only be used to Check whether its true or false.
so Change it to the Service bus body itself and check it.
Thanks,
Sujith.
Sujith
Wednesday, June 13, 2018 5:38 PM
Hey frederik
As the error states, it looks like your `body('XML_Validation')` call is producing a `Null` value whereas xml() call is expecting it to be a string of JSON object. How is your `XML Validate` setup? If it does consistently return string of validated XML, do you really need to run xml() in your xpath()?
Wednesday, June 13, 2018 6:31 PM
Hey
I don't know what XML_Validation returns.
So I tried the following things;
xpath(body('XML_Validation'), '/Document/CustCustomerGroupEntity/PAYMENTTERMID')
This gives the following error:
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2965': 'The template language function 'xpath' expects its first parameter to be an XML object. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#xpath for usage details.'.
When I try: xpath(triggerbody(), '/Document/CustCustomerGroupEntity/PAYMENTTERMID')
Then I get this error
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2966': 'The template language function 'xpath' expects its first parameter to be an XML object. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#xpath for usage details.'.
And when I try: xpath(xml(triggerbody()), '/Document/CustCustomerGroupEntity/PAYMENTTERMID')
I get:
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2966': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'outputs.body.ContentType'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.InvalidTemplate. Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2966': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'outputs.body.ContentType'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.
At last I tried the following Xpath: xpath(xml(base64ToString(triggerBody()?['ContentData'])), '/Document/CustCustomerGroupEntity/PAYMENTTERMID')
but this returns
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email' inputs at line '1' and column '2966': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'Data at the root level is invalid. Line 1, position 1.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.
Wednesday, June 13, 2018 8:54 PM
Hi Sujith,
Thanks a lot, it now works!
I'm a little bit surprised that I have to cast the SB message to a binary.
In the XML validation step, logic apps did automatically a casting to base64toString.
Anyway, it solved :)