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

Using xPath on an HTTP xml body

Hi, 

I'm trying to change the xml format of an HTTP request to JSON format using the xpath expression in flow. 

 

Here is my xml :

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xml:base="https://tenant.sharepoint.com/sites/sitename/_api/">
<id>d1fd24b2-eeb1-4820-a545-f071653f467e</id>
<title/>
<updated>2017-12-01T10:40:43Z</updated>
<entry m:etag="&quot;4&quot;">
    <id>cda821b5-e13b-4dff-9c2e-5be55f5fa3d1</id>
    <category term="SP.Data.EmployeesListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
    <link rel="edit" href="Web/Lists(guid'5b359dba-549b-4210-8afa-5e4fe2aeb166')/Items(3431)"/>
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/LineManager" type="application/atom+xml;type=entry" title="LineManager" href="Web/Lists(guid'5b359dba-549b-4210-8afa-5e4fe2aeb166')/Items(3431)/LineManager">
    <m:inline>
        <entry>
            <id>4f07e464-50cd-4faf-8324-8a4b26878b5a</id>
            <category term="SP.Data.UserInfoItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
            <title/>
            <updated>2017-12-01T10:40:43Z</updated>
            <author>
                <name/>
            </author>
            <content type="application/xml">
            <m: properties>
                <d:EMail>testemail@test.com</d:EMail>
                <d:Title>ps admin</d:Title>
            </m: properties>
        </content>
    </entry>
</m:inline>
</link>
<title/>
<updated>2017-12-01T10:40:43Z</updated>
<author>
    <name/>
</author>
<content type="application/xml">
<m: properties>
    <d: PSFullName>PS Employee</d: PSFullName>
</m: properties>
</content>
</entry>
</feed>

Here is my expression : 

xpath(xml(body('Invoke_an_HTTP_request')), string('/feed/entry/link[2]/m:inline/entry/content/m: properties/d:EMail'))

 

I get the follwing error :

 

InvalidTemplate. Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '2158': 'The template language function 'xpath' parameters are invalid: the 'xpath' parameter must be a supported, well formed XPath expression. Please see https://aka.ms/logicexpressions#xpath for usage details.'.

 

The desired result is to retrieve the email address in the <d:Email > tag.

 

Thanks for any help in advance, 

Macaurly. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
spg-john-liu
Level 8

Re: Using xPath on an HTTP xml body

why aren't you receiving that request in JSON?

gonna play with this a bit.

 

 

the main issue with the XPath here is because of the namespaces.  XPath probably doesn't know what m or d are.

 

to perform query without caring about the namespace, you can use local-name()

 

try:

 

xpath(xml(outputs('Compose')), '//*[local-name()="properties"]/*[local-name()="EMail"]/text()')

Compose = XML string

View solution in original post

7 REPLIES 7
spg-john-liu
Level 8

Re: Using xPath on an HTTP xml body

why aren't you receiving that request in JSON?

gonna play with this a bit.

 

 

the main issue with the XPath here is because of the namespaces.  XPath probably doesn't know what m or d are.

 

to perform query without caring about the namespace, you can use local-name()

 

try:

 

xpath(xml(outputs('Compose')), '//*[local-name()="properties"]/*[local-name()="EMail"]/text()')

Compose = XML string

View solution in original post

garrytrinder
Level: Power Up

Re: Using xPath on an HTTP xml body

Thanks for the reply John Smiley Happy

 

Its a bit of a long story really as to why its coming back as XML. We have a list that exceeds the lookup limit in SharePoint Online, but because there is no $select on the SharePoint connector it fails as it tries to return too much data, as a work around we are using the Azure AD HTTP Connector which has no option to pass headers so it comes back as XML, hence why we are here Smiley Happy

 

I'll try the XPath suggestion you posted, thank you.

Macaurly
Level: Powered On

Re: Using xPath on an HTTP xml body

Thanks John, this solves our problem Smiley Happy

AnshulS
Level: Powered On

Re: Using xPath on an HTTP xml body

hi, 

 

i have a similar issue here, but i am a bit confused about the wokraround you mentioned. what exactly does compose action have in "Compose = XML String"?

 

thanks in advance. 

spg-john-liu
Level 8

Re: Using xPath on an HTTP xml body

write that expression in a Compose action.

Compose is used like a "build string" action here - use the expression editor to enter the formula in a Compose to extract the fields you want through XPath
rgparisoto
Level: Powered On

Re: Using xPath on an HTTP xml body

Very very very helpfull!!!

rgparisoto
Level: Powered On

Re: Using xPath on an HTTP xml body

Guys!

Whats I have to do to get this three items?

 

XMLDuplicatas.png

 

Thank you for any help.

Robson.

 

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: 169 members 3,628 guests
Please welcome our newest community members: