To add, Matt:

The alternative (and actually preferred) method with DOM-Lingo would be to
just create a TreeWalker, with the <b1> element as it's root. Here's all the
code, from parsing to walking:

loParser = new(script "DOM_Parser")
loParser.parseString(lsMyXML)
loDoc = loParser.getDocument()
loB1Elem = loDoc.getElementsByTagName("b1").getItem(0)
loWalker = loDoc.createTreeWalker(loB1Elem, #SHOW_ELEMENT, VOID, TRUE)
loChildNode = loWalker.firstChild()
repeat while not voidP(loChildNode)
  -- work with the child node here
  loChildNode = loWalker.nextSibling()
end repeat

The repeat loop would walk through all the children of the <b1> element
(which is the parent root), and the call the loWalker.nextSibling() would
return VOID when there were no more siblings.

Christopher Watson
Sr. Software Engingeer
Director/Shockwave Development
Lightspan, Inc.
Tel: 858.824.8457
Fax: 858.824.8008


-----Original Message-----
From: Watson, Christopher [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 28, 2002 10:21 AM
To: '[EMAIL PROTECTED]'
Subject: RE: <lingo-l> XML with unkown amount of children


Matt,

If you're using the XML Parser Xtra, then every child node in the tree has a
"count" property which will tell you how many children there are for that
node. In your example, you can loop through the children of the <b1> element
node like this:

repeat with i = 1 to parserObj.child[1].child[2].child.count
  loChildElem = parserObj.child[1].child[2].child[i]
  -- work with the child element
end repeat

If you're using DOM-Lingo, it would be:

loChildNodeList =
loDoc.getElementsByTagName("b1").getItem(0).getChildNodes()
repeat with i = 0 to (loChildNodeList.getLength() - 1)
  loChildElem = loChildNodeList.getItem(i)
  -- work with the child element
end repeat
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to