FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

XML Tutorial: Using the Microsoft XML parser

jawahar
5/2/2005 12:55:23 AM, Views: 3151
The Microsoft XML parser

MSXML Parser 2.5 is the XML parser that is shipped with Windows 2000 and IE 5.5.

MSXML Parser 3.0 is the XML parser that is shipped with IE 6.0 and windows XP.

Once you have installed Internet Explorer, the parser is available to scripts, both inside HTML documents and inside ASP files. The MSXML 3.0 parser features a language-neutral programming model that supports:

JavaScript, VBScript, Perl, VB, Java, C++ and more
Complete XML support
Full DOM and Namespace support
DTD and validation
Complete XSLT and XPath support
SAX2
Server-safe HTTP

To create an XML Document Object with JavaScript, use the following code:

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


To create an XML Document Object with VBScript, use the following code:

set xmlDoc=CreateObject("Microsoft.XMLDOM")


To create an XML Document Object in ASP (with VBScript), use the following code:

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


The Mozilla XML Parser

Plain XML documents are displayed in a tree-like structure in Mozilla (just like IE).

Mozilla also supports parsing of XML data that resides in a file, using JavaScript. The parsed data can be displayed as HTML.

To create an XML Document object with JavaScript in Mozilla, use the following code:

var xmlDoc=document.implementation.createDocument("ns","root",null)


The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.
Loading an XML File Into the Parser

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

<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
...
...
...
</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 turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.

Loading XML Text Into the Parser

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

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

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(txt)
...
...
...
</script>


Note that we have used the "loadXML" method (instead of the "load" method) to load a text string.
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Avg Visitor Rating: Average Visitor Rating is 2.5 out of 5
Number of Ratings : 3 Votes
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
XML RSS Feed
jsamwini
Most Popular Tutorial
Most Popular Solution
No Records!
Top Rated
Top Rankers
Overall
1. jawahar (100)
2. charlie_fink (50)
Yearly -2008
No Rankings!
Expertsforge Sponsors
bnrtop