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

Unable to write a proper xpath

Dear All,

 

I want to extract value of "w:val" attribute in "w:id" and "w:tag" tag from the following xml:

<w:sdtPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
   <w:rPr>
      <w:rFonts w:ascii="Arial" w:cs="Arial" w:hAnsi="Arial"/>
      <w:b/>
      <w:noProof/>
      <w:sz w:val="20"/>
      <w:szCs w:val="20"/>
   </w:rPr>
   <w:alias w:val="legal_entity"/>
   <w:tag w:val="legal_entity"/>
   <w:id w:val="-1760514947"/>
   <w:placeholder>
      <w:docPart w:val="F0003948BDB4448AAEA4C633D11CD157"/>
   </w:placeholder>
   <w:text/>
</w:sdtPr>

 

I have tried some xpath:

xpath(Xml(outputs('Compose')),'//w:sdtPr/*[self::w:id]/text()')

xpath(Xml(outputs('Compose')),'//w:sdtPr/w:id/@w:id')

xpath(Xml(outputs('Compose')),'//w:sdtPr/w:id/*[@w:id]')

 

Please guide me.

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

I tried xpath but also could not make it work, so I tried a different approach. Instead of parsing the XML I converted it back to JSON:

xpath.png

The two expressions I used to extract the ID and the Tag attributes values were:

outputs('JSON')['w:sdtPr']['w:id']['@w:val']
outputs('JSON')['w:sdtPr']['w:tag']['@w:val']

See how you get on with this.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

 

View solution in original post

3 REPLIES 3
Paulie78
Super User
Super User

I tried xpath but also could not make it work, so I tried a different approach. Instead of parsing the XML I converted it back to JSON:

xpath.png

The two expressions I used to extract the ID and the Tag attributes values were:

outputs('JSON')['w:sdtPr']['w:id']['@w:val']
outputs('JSON')['w:sdtPr']['w:tag']['@w:val']

See how you get on with this.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

 

Agrawalramakant
Frequent Visitor

Thanks @Paulie78 for helping me out here.

 

I have a followup question, I hope you do not mind helping there too.

 

Now I want to go through a excel table and for each row I want to get the value of the column which matches the tag  value and associate it with the corresponding id value.

There is no data structure like map or dictionary in Power automate flow, can you guide me how to achieve it?

It would be better to ask a new question and explain carefully what you want to do based on the JSON that you now have.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (4,099)