cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
amarkit
Level: Powered On

Parsing XML with xpath

I am trying to extract the text contained within the <description> of this XML file: https://feeds.everbridge.net/feeds/337829242601583/cap/5d10fe6b69458e4e83c96a5e.xml.

 

xml.jpg

 

Flow is pulling the body of the file succesfully. The Body output of the HTTP step is:

<?xml version="1.0" encoding="UTF-8"?>
<alert xmlns="urnSmiley Surprisedasis:names:tc:emergency:cap:1.2"><identifier>351710576926344</identifier><sender>351710576926344</sender><sent>2019-06-24T09:46:35-07:00</sent><status>Actual</status><msgType>Alert</msgType><scope>Public</scope><code>CAPSv1.2</code><info><language>en-US</language><category>Geo</category><event>Practice/Demo Warning</event><urgency>Immediate</urgency><severity>Extreme</severity><certainty>Observed</certainty><eventCode><valueName>SAME</valueName><value>DMO</value></eventCode><expires>2019-06-24T10:46:35-07:00</expires><senderName></senderName><headline>TEST RSS Template</headline><description>Testing RSS as a template. Message copied, da da da.</description></info></alert>

which matches what I see when I load the XML file directly in a browser.

 

But I can't seem to get the xpath syntax correct. I'm using: 

xpath(xml(body('HTTP')), 'string(//description)')

in the Compose step. No errors are returned, but the input and output of the Compose step are blank. I'm sure my xpath syntax is wrong, but I can't seem to find the permutation that gets it right.

 

Any help would be much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
amarkit
Level: Powered On

Re: Parsing XML with xpath

Thanks, @v-yamao-msft. I rewrote the xpath query as 

xpath(xml(body('HTTP')), '//*[local-name()="alert"]/*[local-name()="info"]/*[local-name()="description"]/text()')

to avoid the XML namespace, per the discussion here. That seems to have solved it.

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Parsing XML with xpath

Hi @amarkit ,

 

The issue could be reproduced.

 

However, I am afraid that it is caused by the “xmlns” in the XML file.

 

I have tested by removing xmlns="urnSmiley Surprisedasis:names:tc:emergency:cap:1.2" from the file, then it works as expected.

1.PNG2.PNG

 

Besides, the following thread could be helpful as well:

https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
amarkit
Level: Powered On

Re: Parsing XML with xpath

Thanks, @v-yamao-msft. I rewrote the xpath query as 

xpath(xml(body('HTTP')), '//*[local-name()="alert"]/*[local-name()="info"]/*[local-name()="description"]/text()')

to avoid the XML namespace, per the discussion here. That seems to have solved it.

 

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 233 members 4,006 guests
Please welcome our newest community members: