cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Suhasuser
Regular Visitor

Trouble while parsing xml in logic apps. Flow reads xml from blob and writes to DB

Hi All,

 

Following is the xml that I facing trouble with :

 

<?xml version="1.0" encoding="utf-16"?>

<ItemNotification>
        <MessageHeader>
             <MessageID>PABG0103329120200130120241</MessageID>
        </MessageHeader>
        <ItemList>
           <Item>
               <PartNumber>BG01033291</PartNumber>
               <AfterMarketClass/>
              <ApproverDate>2018-11-08</ApproverDate>
         </Item>
      </ItemList>
</ItemNotification>

 

I have tried the following xpath for parsing:

xpath(xml(string(body('Get_blob_content_using_path'))),'string(/ItemNotification/ItemList/Item/PartNumber/text()')

xpath(xml(string(body('Get_blob_content_using_path'))),'string(//PartNumber/text()')

 

I need the Text in PartNumber node. Also tried de-batching this in a For Each loop (not required but tried it). 

 

Following is my flow:

image.png

 

 

 

 

 

 

 

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
abm
Super User III
Super User III

Hi @Suhasuser 

 

XPath expression failed to parse XML for UTF-16  so I did changed the first line of your XML to

 

<?xml version="1.0" encoding="utf-8"?>

 

or 

 

<?xml version="1.0"?>

 

Try the following steps:

 

image.png

 

Below is the expression I used.

xpath(xml(outputs('Compose_2')),'//ItemList/Item/PartNumber/text()')
 
image.png
 
 
 


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

abm
Super User III
Super User III

Hi @Suhasuser 

 

Create a compose and map the XML.

 

Next add another compose to use the replace.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

6 REPLIES 6
abm
Super User III
Super User III

Hi @Suhasuser 

 

XPath expression failed to parse XML for UTF-16  so I did changed the first line of your XML to

 

<?xml version="1.0" encoding="utf-8"?>

 

or 

 

<?xml version="1.0"?>

 

Try the following steps:

 

image.png

 

Below is the expression I used.

xpath(xml(outputs('Compose_2')),'//ItemList/Item/PartNumber/text()')
 
image.png
 
 
 


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

Suhasuser
Regular Visitor

Yes, that was the kink giving me the error. Problem solved. Thanks to you.

Suhasuser
Regular Visitor

How to deal with this problem. I keep getting this xml from upstream how do read this using xpath in logic app if all xmls are utf-16  encoded ? Can you please give some suggestions ?

abm
Super User III
Super User III

Hi @Suhasuser 

 

Thanks for the update. 

 

You could use a replace expression to change the XML UTF value.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials
Suhasuser
Regular Visitor

Hi ,

 

I have used the following expression to replace the string from utf-16 to utf-8 :

replace(string(triggerBody()?['Path']),'utf-16','utf-8')
 
But it has not replaced as i can see in the output
 
image.png
abm
Super User III
Super User III

Hi @Suhasuser 

 

Create a compose and map the XML.

 

Next add another compose to use the replace.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (53,008)