Jump to content

Recommended Posts

  • Moderators

Modern browsers have an enormous number of built-in functions, sometimes very handy

These ones, having to do with tree handling, came up the other day : domParsing, nodeIteration and treeWalking

The built in domParser function takes a tree in html/dom or xml format :

   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer''s Guide</title>
      <description>An in-depth look at creating applications
      with XML.</description>

which can be used as in

var oDOM: variant := new JObject;

var oParser = new DOMParser();
@oDOM = oParser.parseFromString(@theaboveXMLstring, "application/xml");

writeln(oDOM.documentElement.nodeName);                     // root (catalog)
writeln(oDOM.children[0].children[0].attributes[0].name);   // id
writeln(oDOM.children[0].children[0].attributes[0].value);  // bk101


To traverse these types of trees, there are also the following functions available : nodeIterator and treeWalker

These functions are largely similar. The nodeIterator :

var nodeIterator : variant := new JObject;
nodeIterator := oDOM.createNodeIterator(
    oDOM.documentElement,-1);        // NodeFilter.SHOW_ELEMENT : -1 or 0xFFFFFFFF

var currentNode := nodeIterator.nextNode();
while currentNode <> null do begin      // null = eof
  // get rid of whitespace text nodes
  if currentNode.nodeName <> '#text' then begin
  currentNode := nodeIterator.nextNode();



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...