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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Key value pair in powe...
Power Automate
Unanswered

Key value pair in power automate

(0) ShareShare
ReportReport
Posted on by 180

<info>
<user name=“user1” age=“21”/>
<user name=“user2” age=“22”>

<user name=“user3” age=“23”/>

<user name=“user4” age=“24”/>
</info>

 

How to build Key value pair based on name and age using above xml?

Thanks,

Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,716 Super User 2026 Season 1 on at

    Your XML is malformed. Please refer to  https://aka.ms/logicexpressions#xml

     

    Should be more like

     

     

    <?xml version="1.0"?>
    <info>
    <user name='user1' age='21'/>
    <user name='user2' age='22'/>
    <user name='user3' age='23'/>
    <user name='user4' age='24'/>
    </info>

     

     

    Then you can use xpath to get to the attributes and with a Select statement you can create your key/value pairs as needed.

     

    xpath(xml(variables('Test')),'//@name'),
    xpath(xml(variables('Test')),'//@age')

     

    What does your expected output look like?

     

     

     

     

  • Ellis Karim Profile Picture
    12,109 Super User 2026 Season 1 on at

    Hi @Shafdev ,

     

    You could try the following flow. It required a few more actions than I was expecting:

     

    Snag_863fdb.png

     

    Snag_869985.png

    <info>
     <user name="user1" age="21"/>
     <user name="user2" age="22"/>
     <user name="user3" age="23"/>
     <user name="user4" age="24"/>
    </info>

    Snag_871c70.png

    xml(outputs('Compose'))

     

    Snag_892129.png

    From:
    xpath(outputs('Compose_XML'),'/info/user/@name')
    
    Map:
    replace(replace(item(), 'name="',''), '"','')

     

    Snag_8a3cea.png

    From:
    xpath(outputs('Compose_XML'), '/info/user/@age')
    
    Map:
    replace(replace(item(), 'age="',''), '"','')

    Snag_8b1866.png

    From:
    range(0, length(body('Select_Name')))
    
    name:
    body('Select_Name')?[item()]
    
    age:
    body('Select_Age')?[item()]
    

     

    This is the runtime output:

    Snag_906b11.png

     

    When I used XPath to extract the name and age attributes (in steps 3 and 4) , Power Automate returned the attribute along with the values in this format, which wasn't what I was expecting:

    [
     "name=\"user1\"",
     "name=\"user2\"",
     "name=\"user3\"",
     "name=\"user4\""
    ]

     

    So, after extracting the data using XPath, I used some expressions to manipulate the string and extract just the value part:

    [
     "user1",
     "user2",
     "user3",
     "user4"
    ]

     

    Hope this helps.


    Ellis
    ____________________________________
    If I have answered your question, please mark the post as ☑️ Solved.
    If you like my response, please give it a Thumbs Up.
    My Blog Site

  • Chriddle Profile Picture
    8,697 Super User 2026 Season 1 on at

    Chriddle_0-1713104998902.png

    json(xml(outputs('Compose')))['info/user']

     

    Chriddle_1-1713105038682.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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 382

#2
Valantis Profile Picture

Valantis 370

#3
David_MA Profile Picture

David_MA 300 Super User 2026 Season 1

Last 30 days Overall leaderboard