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.
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)')
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=', ''), '"', '')
This would give the following output:
[
"Smith, John",
"Anderson, Thomas",
"Moss, Carrie-Anne"
]
stampcoin
97
Michael E. Gernaey
82
Super User 2025 Season 1
David_MA
48
Super User 2025 Season 1