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

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 V
Helper V

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 Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,979)