Announcement

Collapse
No announcement yet.

Loop through XML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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>

  • #2
    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

    Comment


    • #3
      Source Transformer step. I was hoping to get some help with the javascript code for this. P

      Comment


      • #4
        for each(seg in msg['house'].children())
        {
        if(seg.name() != 'Kitchen.Mop')
        {
        }
        }

        Comment


        • #5
          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");
          }
          }

          Comment


          • #6
            Sorry. Had the structure of the message incorrect...

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

            Comment


            • #7
              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, 12:50 PM.

              Comment


              • #8
                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");
                }
                }

                Comment

                Working...
                X