When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Software Developer / Programmer
Next Step Systems
US-IL-Des Plaines

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, May 10, 2000

Getting Started with XML, Part 2


  • Read Part 1

  • In Part 1 we looked at a basic XML file that stored widget information. In this part we'll look at how to use the XMLDOM to parse through the XML file created in Part 1.

    - continued -

    Microsoft provides the XML DOM (Document Object Model) to assist with parsing an XML document. This DOM can be accessed through the browser if it is an XML-enabled browser (Internet Explorer 5.0) using client-side script; the XML DOM is also available on the server-side. To create an instance of the XML DOM, use the following line of code:

    Dim objXMLDOM
    Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")
    

    Internet Explorer 5.0 must be installed on your Web server for this to work. If it is not you will get an error when trying to create an instance of the Microsoft.XMLDOM component.

    There are a ton of methods, properties, and events for the XML DOM, all of which can be found on Microsoft's XML Documentation Site. For the remainder of this article we will be using the XML document created in Part 1, widget.xml. To load a document into the XML parser, use the load method like so:

    Dim objXMLDOM
    Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")
    
    'load the widget.xml document
    objXMLDOM.load(Server.MapPath("widget.xml"))
    

    Since the load method expects the physical path of the XML document, we used the Server.MapPath method.

    Then, use a number of the XML methods to iterate through the document. When loaded, the root node becomes the active node. In the widget.xml XML file, the widgets tag was the root node. We can use the childElements collection to iterate through all of the root node's children like so:

      for each objChild in objXMLDOM.documentElement.childNodes
        Response.write objChild.NodeName & " - "    
        response.write objChild.Text & "<BR>"
      next
    

    The NodeName property displays the name of the node (widget) while the Text property lists the contents of the node. The XML DOM is a very collection-intensive tool - when iterating through an XML document you usually will need to visit each node; each node will have a collection of children nodes, which, in turn, might each have a collection of children nodes themselves, and so on... For more information on these collections it is highly recommended that you check out Microsoft's XML Documentation Site.

  • See a live demo of the code presented above!

    Happy Programming!


    Attachments:

  • View the widget.xml XML document

    Recommended Articles/Sites/Books:

  • XML101.com
  • Professional XML Design & Implementation
  • Microsoft's XML Documentation Site


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers