web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Getting XML attribute ...
Power Automate
Answered

Getting XML attribute using XPATH

(0) ShareShare
ReportReport
Posted on by 578

 have an XML that looks like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:comments>
 <w:comment w:author="Smith, John" w:date="2023-10-06T12:26:00Z" >
 <w:p w:rsidR="00294E10" w:rsidP="007202C8" w:rsidRDefault="00294E10" w14:paraId="3DA74C72" w14:textId="77777777">
 <w:pPr>
 <w:pStyle w:val="CommentText" />
 <w:ind w:left="0" />
 </w:pPr>
 <w:r>
 <w:rPr>
 <w:rStyle w:val="CommentReference" />
 </w:rPr>
 <w:annotationRef />
 </w:r>
 <w:r>
 <w:t>Comment 1</w:t>
 </w:r>
 </w:p>
 </w:comment>
 <w:comment.....

 

I pull the text I need from "w:t" using:

xpath(outputs('Compose_XML'), '//*[name()=''w:t'']/text()')

//Response: 
[
 "Comment 1",
 "Comment 2",
 "Comment 3"
 ]

 

The issue is that I'm having a hard time getter the attribute "w:author" text. I'm using:

//Option 1:
xpath(outputs('Compose_XML'), '//*[name()=''w:comment'']/@*[name()=''w:author'']') 

//Option 2:
xpath(outputs('Compose_XML'), '//@*[name()="w:author"]')

//Response:
[
 "w:author=\"Smith, John\"",
 "w:author=\"Anderson, Thomas\"",
 "w:author=\"Moss, Carrie-Anne\""
]

 

Both options give me a text with extra quotes, backslashes and '"w:author=\". How can I just get the names (e.g. Smith, John)?

 

Thanks in advance.

Categories:
I have the same question (0)
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Power Automate really needs to improve on its XPath implementation. What you have "should" only return the value of each attribute. I've tried numerous ways to try and get just the value but no luck.

     

    A workaround is to do the following. Use a Select to get the initial output from the XPath expression, then use replace to remove the prefix and double quotes.

     

    //From
    xpath(outputs('Compose_XML'), '//@*[name()="w:author"]')
    
    //Map
    replace(replace(item(), 'w:author=', ''), '"', '')

     

    grantjenkins_1-1698454704791.png

     

    This would give the following output:

     

    [
     "Smith, John",
     "Anderson, Thomas",
     "Moss, Carrie-Anne"
    ]

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    A slightly better approach that doesn't use the replace expression is below.

     

    //From
    xpath(xml(outputs('Compose_XML')), '//*/w:comment[@author]')
    
    //Map
    xpath(item(), 'string(//@w:author)')

    grantjenkins_0-1698455857794.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard