powershell - How to loop through grouped XML nodes -


i have xml document in format

<rss>   <channel>     <item>       <id>1</id>       <image>img_32.jpeg</image>     </item>     <item>       <id>2</id>       <image>img_42.jpeg</image>     </item>     <item>       <id>1</id>       <image>img_52.jpeg</image>     </item>     <item>       <id>3</id>       <image>img_62.jpeg</image>     </item>     <item>       <id>4</id>       <image>img_72.jpeg</image>     </item>   </channel>   </rss> 

the id node not unique. i'd using powershell group id, loop through grouped items each id.

id 1 has 2 images   loop through 2 images      id 2 has 1 image   loop through 1 image      etc.. 

so far have following:

[xml]$xml = (new-object system.net.webclient).downloadstring("https://myfeedurl.xml") $grouped = $xml.rss.channel.item | group id $grouped 

which returns

count name        group ----- ----        -----     2 1           {item}{item}     1 2           {item}     1 3           {item}     1 4           {item}

but can't figure how use grouped information in order end list of unique grouped id items can loop through images.

the group property of each item returned group-object contains group elements - need nested loop:

foreach($group in $grouped) {   "processing images id $($group.name)"   foreach($image in $group.group)   {     "processing $($image.name)"   } } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -