cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dennisb88
Helper III
Helper III

Convert xml to dynamic data

Hi all,

 

I've a question about how I can turn specific records in my XML data into dynamic content?

unfortunately there is no Rest API/JSON available to connect with.

 

For Example, how can I get the info, like as the address,city etc. as dynamic content available to use in my next steps. (Like as how it works with parse json.)

<?xml version="1.0" encoding="UTF-8"?>

<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <orderperson>John Smith</orderperson>
  <shipto>
    <name>Ola Nordmann</name>
    <address>Langgt 23</address>
    <city>4000 Stavanger</city>
    <country>Norway</country>
  </shipto>
  <item>
    <title>Empire Burlesque</title>
    <note>Special Edition</note>
    <quantity>1</quantity>
    <price>10.90</price>
  </item>
  <item>
    <title>Hide your heart</title>
    <quantity>1</quantity>
    <price>9.90</price>
  </item>
</shiporder>

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

For that just change the xpath you are using like this

 

xpath(xml(variables('varXML')),'string(/shiporder//item[1]/price)') -> 10.90

xpath(xml(variables('varXML')),'string(/shiporder//item[2]/price)') -> 9.90

 

//item - retrieves all the item elements at that level

[2] is the index to retrieve the second item from all the items.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

4 REPLIES 4
Pstork1
Dual Super User III
Dual Super User III

If you treat the input as XML you can read specific values using XPath.  If you load each XPath into a Compose or Variable you'll have the values as dynamic content.  For example to get the Name field using

xpath(xml(variables('varXML')),'string(/shiporder/shipto/name)')

Where varXML is a string variable with the XML in it.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi @Pstork1 ,

Thank you, that is helping a lot. 

But how can I get both values of "price". In the example I've two price columns.

 

When I use:

xpath(xml(variables('varXML')),'string(/shiporder/item/price)')

I get only the first result back, how can I make a difference between this two?

 

Thanks in advance.

Pstork1
Dual Super User III
Dual Super User III

For that just change the xpath you are using like this

 

xpath(xml(variables('varXML')),'string(/shiporder//item[1]/price)') -> 10.90

xpath(xml(variables('varXML')),'string(/shiporder//item[2]/price)') -> 9.90

 

//item - retrieves all the item elements at that level

[2] is the index to retrieve the second item from all the items.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

dennisb88
Helper III
Helper III

For anyone else who try to use xml data later in the flow, it's also possible to convert the XML to JSON, that's make it easier to get the same result on a faster way:

 

Below the steps that I've make:

  1. Initialize variable string with inside the xml data.
  2. Create a second Initialize variable string with the follow expression: json(xml(variables('Convert XML to JSON')))
  3. Run the flow
  4. Copy the result of the second initialize variable output.
  5. Add an 'parse json' activity and paste the copied result in "generate from sample.
  6. You have now all the data as dynamic content available.

Flow example:

dennisb88_0-1618391195325.png

 

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (56,079)