Forum Discussion

alex_panganiban's avatar
alex_panganiban
Contributor
3 years ago
Solved

XML Generator Arrays

I'm having an issue with the XML Generator. I feel what I'm doing should work. Hoping someone can enlighten me on what's going on. I have an array that gets passed into the XML Generator snap. For each instance within the input array, I am attempting to get a single XML element with a value created, but instead, I'm getting back an entire object.

Here's my input:

Here's what I have coded in the XML Generator:

And here's the output I receive from the XML Generator.

What I expect and want to receive should look more like this:

 

     <b:guid>e139cd2c-b47c-4247-a25f-acb80122fa8b</b:guid>
</memberIds>
 
And eventually as I test with more data, it should look like this:
     <b:guid>e139cd2c-b47c-4247-a25f-acb80122fa8b</b:guid>
     <b:guid>x139cd2x-x47x-4247-x25x-xxx80122xx8x</b:guid>
     <b:guid>y139cd2y-y47y-4247-a25y-yyy80122yy8y/b:guid>
     <b:guid>z139cd2z-z47z-4247-z25z-zzz80122zz8z</b:guid>
</memberIds>
 
What am I doing wrong? My foreach looks good to me, but something is obviously off. Thanks in advance for the assist.
  • Hi alex_panganiban ,

    You need to accesses to the memberId element of each object.

    You can try with the following:

    #foreach($memberIds in $members)
    <b:guid>$memberIds.memberId</b:guid>
    #end
     
    BR.
    Ivica

2 Replies

  • ivicakoteski's avatar
    ivicakoteski
    New Contributor III

    Hi alex_panganiban ,

    You need to accesses to the memberId element of each object.

    You can try with the following:

    #foreach($memberIds in $members)
    <b:guid>$memberIds.memberId</b:guid>
    #end
     
    BR.
    Ivica
  • Awesome! Thanks Ivica. Your solution made me realize that the "memberIds" element does not actually need to exist in the incoming document. It's actually dynamic. Not knowing that was what was causing my problem. Thanks so much for this learning. My final solution was this:

     

    #foreach($member in $members)
    <b:guid>$member.memberId</b:guid>
    #end