web stats
Loop through XML - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-26-2019, 07:06 AM
gojoshi gojoshi is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 51
gojoshi is on a distinguished road
Default Loop through XML

Hello, I need a way to loop through an XML node like the one shown below. I need to acquire all of the values under Kitchen.Sink, WITHOUT getting any values from Kitchen.Mop.

Thanks for any suggestions.

<house>
<Kitchen.Sink>
<Kitchen.01>1</Kitchen.01>
<Kitchen.02>2</Kitchen.02>
<Kitchen.03>3</Kitchen.03>
<Kitchen.04>4</Kitchen.04>
<Kitchen.05>5</Kitchen.05>
<Kitchen.06>6</Kitchen.06>
<Kitchen.Mop>
<Kitchen.01>A</Kitchen.01>
<Kitchen.02>B</Kitchen.02>
<Kitchen.03>C</Kitchen.03>
<Kitchen.04>D</Kitchen.04>
</Kitchen.Mop>
</Kitchen.Sink>
</house>
Reply With Quote
  #2  
Old 09-26-2019, 07:21 AM
ragas1986 ragas1986 is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 10
ragas1986 is on a distinguished road
Default Question

what do you want to use to loo through? Are you trying to do as part of transformer step? You can use Javscrit or xslt to loop through
Reply With Quote
  #3  
Old 09-26-2019, 07:24 AM
gojoshi gojoshi is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 51
gojoshi is on a distinguished road
Default

Source Transformer step. I was hoping to get some help with the javascript code for this. P
Reply With Quote
  #4  
Old 09-26-2019, 07:40 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,361
cory_cole is on a distinguished road
Default

for each(seg in msg['house'].children())
{
if(seg.name() != 'Kitchen.Mop')
{
}
}
Reply With Quote
  #5  
Old 09-27-2019, 09:48 AM
gojoshi gojoshi is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 51
gojoshi is on a distinguished road
Default

Quote:
Originally Posted by cory_cole View Post
for each(seg in msg['house'].children())
{
if(seg.name() != 'Kitchen.Mop')
{
}
}

Hey Cory, the above isn't working..

I tried this but did not work:

for each(seg in msg['house'].children())
{
if(seg.name() != 'Kitchen.Mop')
{
logger.info("Hi");
}
}
Reply With Quote
  #6  
Old 09-27-2019, 10:44 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,361
cory_cole is on a distinguished road
Default

Sorry. Had the structure of the message incorrect...

for each(seg in msg['Kitchen.Sink'].children())
{
if(seg.name() != 'Kitchen.Mop')
{
logger.info("Hi");
}
}
Reply With Quote
  #7  
Old 09-27-2019, 12:23 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,178
agermano is on a distinguished road
Default

Code:
for each (var node in msg['Kitchen.Sink'].children()) {
    if (node.localName() == 'Kitchen.Mop') continue;
    logger.info(<>node: {node.localName()}, value: {node.toString()}</>);
}
Edit: Sorry, didn't notice Cory had already corrected it. Here's another way to do it.

Last edited by agermano; 09-27-2019 at 12:50 PM.
Reply With Quote
  #8  
Old 09-30-2019, 05:44 AM
gojoshi gojoshi is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 51
gojoshi is on a distinguished road
Default

Thank you agermano and cory_cole, The below is working for me:

for each(seg in msg['Kitchen.Sink'].children())
{
if(seg.name() != 'Kitchen.Mop')
{
logger.info("Hi");
}
}
Reply With Quote
Reply

Tags
loop, xml, xml child segments

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:12 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation