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 / 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,479 Super User 2025 Season 2 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
    11,695 Super User 2025 Season 2 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,443 Super User 2025 Season 2 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

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 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard