cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jm5
Frequent Visitor

Trying to parse xml with xpath

Hi,

 

I'm fairly new to flow and I'm trying to parse the value of EmailId element out of the following xml

 

 

<?xml version="1.0" encoding="utf-16"?>
<SbdRegisterContactRequest
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <OperationId>6789</OperationId>
    <ApiKey>1234</ApiKey>
    <Parameters>
        <Contact>
            <EmailId>tester@testing.com</EmailId>
            <FirstName>test</FirstName>
            <LastName>tester</LastName>
            <Company>testing</Company>
            <JobTitle>tester</JobTitle>
            <TelephoneNumber />
            <Department />
            <PreferredUILanguageCode>eng</PreferredUILanguageCode>
            <CountryCode>GBR</CountryCode>
        </Contact>
    </Parameters>
</SbdRegisterContactRequest>

 

 In the compose step I'm currently using the following formula:

xpath(xml(triggerBody()?['new_requestxml']), '//*[local-name()="SbdRegisterContactRequest"]/*[local-name()="Parameters"]/*[local-name()="Contact"]/*[local-name()="EmailId"]/text()')
 
The new_requestxml field holds the xml that I have shared in string format and hence I'm using it directly within the formula. I keep getting The template language function 'xpath' failed to parse the provided XML error. Any help to resolve this would be appreciated!!
 
Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
v-bacao-msft
Community Support
Community Support

 

Hi @jm5 ,

 

Its encoding is utf-16, it cannot be parsed. It needs to be utf-8.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-bacao-msft
Community Support
Community Support

 

Hi @jm5 ,

 

Its encoding is utf-16, it cannot be parsed. It needs to be utf-8.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

jm5
Frequent Visitor

Thanks @v-bacao-msft , the encoding was indeed the issue. Changing this has solved the problem!!

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.

Top Solution Authors
Users online (1,912)