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="urn:oasis: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
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.

 

View solution in original post

2 REPLIES 2
Highlighted
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="urn:oasis: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.
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.

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

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 Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 382 members 5,727 guests
Please welcome our newest community members: