October 8, 2008

XML “child” Defined

Filed under: XML — Tags: — admin @ 7:36 am

This post clarifies the meaning of “child”. An XML node may have 0 or more child nodes. A child node is a direct descendent of the parent (i.e. it is one level below the parent node).

Methods such as NumChildrenHavingTag will return the number of direct descendents (i.e. nodes that are exactly one level below the calling node) that match the specified requirements.

For more information, see this XML Child Tutorial

September 8, 2008

XML Search Clarification - Breadth-first Search

Filed under: XML — Tags: , — admin @ 12:15 pm

The Chilkat XML component library (for C#, VB.NET, ASP.NET, ASP, VB6, FoxPro, Delphi, C++, C, Perl, Ruby, Python, Java, etc.) has a number of Search* methods. These methods search for a node in the XML document matching a specific criteria. For example, SearchForTag searches for the 1st node that has a tag with a specific value.

The general form of a Search* method is this:

foundNode = subTreeRoot.SearchMethod(startNode, ...)

The part of the XML document that is searched is the sub-tree rooted at the calling node (subTreeRoot). The method does a breadth-first traversal of the XML sub-tree (see http://en.wikipedia.org/wiki/Breadth-first_search for more information about breadth-first traversal). The startNode indicates where the search should begin in the traversal. Any nodes found matching the requirement(s) are ignored until the startNode is traversed. To search the entire sub-tree, pass a NULL reference in startNode. If a matching node is found, a reference (or pointer) to it is returned, otherwise a NULL is returned.

August 1, 2008

XML Methods Ending in “2″ (GetRoot2, GetChild2, GetParent2, NextSibling2, …)

Filed under: XML — Tags: , — admin @ 6:40 am

A Chilkat XML object represents a single node within an XML document. The “root” is the topmost node in the XML document tree. As long as at least a single reference to a node (anywhere in the tree) exists, the entire XML tree remains in memory.

Typically, an XML API returns a new node object when navigating. Chilkat XML does this also. For example:

// Get the 1st child:
Chilkat.Xml childNode = xmlDoc.GetChild(0);

For efficiency, Chilkat provides alternate methods such that instead of returning a new object, the internal pointer of the Chilkat XML object is updated. This can vastly reduce the proliferation of objects that might need to be allocated/deallocated or garbage collected. For example:

xmlDoc.GetChild2(0);
// xmlDoc now references the  1st child.
xmlDoc.GetParent2();
// xmlDoc is now back to where it began.
// Regardless of the location of an XML object in the tree,
// you may always return to the document root like this:
xml.GetRoot2();