Advertise Here
Need an introduction to XML Document Object Models? Learn about document object model parsing, how to parse XML document objects using Microsoft XML, how to find DOM parser errors, and how to test for valid XML display errors in documents. - Web06
Extensible Markup Language

Search XML Files:

XML Files RSS Feed XML Files Updates

 

DEVELOPER CHANNEL
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

Find a Web Host With:
CGI Capabilities
Active Server Pages
Windows Hosting
Unix Hosting
Dedicated Servers
     
 Advanced Search
 Be a Commerce Partner















IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Parsing the DOM

by Jan Egil Refsnes

prev next

Using the XML parser

To read and update - create and manipulate - an XML document, you need an XML parser. The Microsoft XML parser is a COM component that comes with Microsoft Internet Explorer 5.0. Once you have installed IE 5.0, the parser is available to scripts inside HTML documents and ASP files.

The Microsoft XMLDOM parser features a language-neutral programming model that:

  • Supports JavaScript, VBScript, Perl, VB, Java, C++ and more
  • Supports W3C XML 1.0 and XML DOM
  • Supports DTD and validation

If you are using JavaScript in IE 5.0, you can create an XML document object with the following code:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

If you are using VBScript you create the XML document object with the following code:

set xmlDoc = CreateObject("Microsoft.XMLDOM")

If you are using VBScript in an Active Server Page (ASP), you can use the following code:

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

Loading an XML file into the parser

The following code loads an existing XML document (note.xml) into the XML parser:

<script language="JavaScript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
// ....... processing the document goes here
</script>

The first line of the script creates an instance of the Microsoft XML parser. The third line tells the parser to load an XML document called note.xml. The second line assures that the parser will halt execution until the document is fully loaded.

JUST TRY IT new


Loading pure XML text into the parser

The following code loads a text string into the XML parser:

<script language="JavaScript">

var text="<note>"
text=text+"<to>Tove</to><from>Jani</from>"
text=text+"<heading>Reminder</heading>"
text=text+"<body>Don't forget me this weekend!</body>"
text=text+"</note>"

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(text)
// ....... processing the document goes here
</script>

Note that the "loadXML" method (instead of the "load" method) is used to load a text string.


prev next
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 DevX XML Content 
- W3C Has a New XML Standard: XProc
- Create a Map Client with Web Services, Part II
- Why Data as a Service Will Reshape EAI
- Transitioning from XSLT 1.0 to 2.0, Part 2
- Transition from XSLT 1.0 to XSLT 2.0, Part 1

Jump to : Top Of Page or HOME


Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers