Announcement

Collapse
No announcement yet.

iterate over all nodes

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

  • iterate over all nodes

    Hello,

    I need to iterate over all nodes of an xml message to add attributes. do you know how I can do it in javascript?
    WD

  • #2
    for each (node in msg)
    {
    }

    Comment


    • #3
      If the E4X object you want to iterate through is basically a bunch of sibling nodes, then "for each (node in object)" will get you what you want. However, if you want to iterate through the child nodes of a particular object, then you'll need to use "for each (node in object.children())". Or, you can account for both cases at once:

      Code:
      for each (node in object) {
      	for each (child in node.children()) {
      		// Do something
      	}
      }
      Or:

      Code:
      for each (node in object) {
      	for each (child in node.elements()) {
      		// Do something
      	}
      }
      Alternatively, you can take a single E4X object and recursively iterate through all descendant nodes, including inner text elements:

      Code:
      for each (element in object.descendants()) {
      	// Do something
      }
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment


      • #4
        I did that but I don't the structure of the received xml can be different so i dont' know the depth. I will need to do recursive function.
        Merci Narupley
        WD

        Comment


        • #5
          Originally posted by cory_cole View Post
          for each (node in msg)
          {
          }
          This will not loop through childs
          WD

          Comment

          Working...
          X