BizTalk Utilities CV ,   Jobs ,   Code library  
 
 

Microsoft DOM Objects Reference

Download ReferenceDownload this Reference 

Previous PageTable Of ContentsIndexNext Page

childNodes

Is a member of:
DOMDocument
XMLDOMNode
XMLDOMAttribute
XMLDOMCDATASection
XMLDOMComment
XMLDOMDocumentFragment
XMLDOMDocumentType
XMLDOMElement
XMLDOMEntity
XMLDOMEntityReference
XMLDOMNotation
XMLDOMProcessingInstruction
XMLDOMText
XTLRuntime

Syntax

set objXMLDOMNodeList = objXMLDOMNode.childNodes

Remark

This property is read-only. The childNodes property returns the IXMLDOMNodeList collection object of the child Nodes for the parent object. Each Node that is returned from the child Node, may have childNodes themselves, which is consistent with the tree metaphor that the DOMDocument uses.

Example

Dim objDOMDocument As DOMDocument

Dim objXMLDOMNodeList As IXMLDOMNodeList

Set objDOMDocument = New DOMDocument

objDOMDocument.async = False

objDOMDocument.Load "http://localhost/xmlcode/people2.dtd"

Set objXMLDOMNodeList = objDOMDocument.documentElement.childNodes

      ¬ For the following explanations, we will use this XML example:

<?xml version="1.0" ?>

<!-- *********** Resumes for People *********** -->

<!DOCTYPE PEOPLE SYSTEM "http://localhost/xmlcode/people.dtd">

<PEOPLE>

<PERSON id="1">

<NAME>Mark Wilson</NAME>

<ADDRESS>911 Somewhere Circle, Canberra, Australia</ADDRESS>

<TEL>(++612) 12345</TEL>

<FAX>(++612) 12345</FAX>

<EMAIL>markwilson@somewhere.com</EMAIL>

</PERSON>

<PERSON id="2">

<NAME>Tracey Wilson</NAME>

<ADDRESS>121 Zootle Road, Cape Town, South Africa</ADDRESS>

<TEL>(++2721) 531 9090</TEL>

<FAX>(++2721) 531 9090</FAX>

<EMAIL>Tracey Wilson@somewhere.com</EMAIL>

</PERSON>

</PEOPLE>

Common uses of the childNode property are:

      ¬ the child Node of the DOMDocument root consists of the processing instructions, DTDs, etc.

      ¬ the child Node of the root element consists of all the data in the DOMDocument

      ¬ the child Node of the attributes property of an element

      ¬ consists of the collection of attributes for the given element

What's so good about the childNodes property?

      ¬ Because the childNodes property is an XMLDOMNodeList collection, it is easy to iterate through, to collect the data.

      ¬ You can use the XMLDOMNode object to iterate through the XMLDOMNodeList collection, as it receives most of the other type of interfaces. See later in this section, "Iterating throughthe childNodes."

Getting the childNodes from the root of the DOMDocument

Here we look for the child Nodes of the actual root of the complete DOMDocument. To get these child Nodes from VB, our code would read:

set objXMLDOMNodeList = objDOMDocument.childNodes

      ¬ This will return the four child Nodes shown in figure  .

      ¬ You might have noticed that we have specified the Nodetypes returned from each child Node. Please see the nodeType property for more details on these types of Nodes.

Getting the childNodes from the documentElement element of the DOMDocument

This property returns all the Nodes associated with root Node, which is found in the documentElement property of the DOMDocument (i.e., all the PERSON's in the PEOPLE element).To get the childNodes from VB, our code would read:

set objXMLDOMNodeList = objDOMDocument.document-Element.childNodes

From our example, two child Nodes will be returned in this NodeList object, as shown in figure  .

Getting all the childNodes from a single element

We now want to return all the elements between each section:

<PERSON PERSONID="p2">

...

</PERSON

This returns the NAME, ADDRESS, TEL, etc. This is the base of the child Nodes, but even these childNodes can once again iterate down to more childNodes, if they themselves have children.

In the following XML example, the child Node of Mark Wilson is Male:

<PERSON PERSONID="p2">

<NAME>Mark Wilson</NAME>

<GENDER>Male</GENDER>

<ADDRESS>

...

</PERSON

In our main example in table  , there are five child Nodes found for each Person element, as shown in figure  .

Iterating through the childNodes

Because an IXMLDOMNodeList collection is returned from the childNodes property, you can iterate through each item using a for each ... next loop. Here we demonstrate looping through the collection of child Nodes returned from the documentElement property:

For Each objNode In objDOMDocument.document-Element.child-Nodes

    populateTreeWithChildren objNodeNext

The objNode has been declared as an IXMLDOMElement.

      ¬ Note that an XMLDOMNodeList object is returned even if there are no children of the Node. In such a case, the length of the list will be set to zero. To get the length of the XMLDOMNodeList, use:

if objPeopleRoot.length > 0 then

...

end if

Previous PageTable Of ContentsIndexNext Page

This manuscript is an abridged version of a chapter from the Manning Publications book XML Programming with VB and ASP. This chapter looks at the Microsoft DOM objects. NOTE: Most images have been removed to increase speed and many of the code comments have also been removed for presentation. Please purchase the book to enjoy the full experience of all the chapters with images and code comments!

 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




Chicago Web Site Design
spfxmasks
conference calling
Versace sunglasses
air freshener
odor remover


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP