Please visit our sponsors !
The Microsoft XML Parser
To read and update - create and manipulate - an XML document, you need an XML parser.
Using the XML parser
The Microsoft XML parser comes with Microsoft Internet
Explorer 5.0.
Once you have installed IE 5.0, the parser is available to
scripts, both inside HTML documents and inside ASP files. The parser features a language-neutral programming model
that supports:
- JavaScript, VBScript, Perl, VB, Java, C++ and more
- W3C XML 1.0 and XML DOM
- 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 ASP, you can use the following code:
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
|
Loading an XML file into the parser
XML files can be loaded into the parser using script code.
The following code loads an 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")
// ....... processing the document goes here
</script>
|
The second line in the code above creates an instance of the Microsoft XML parser.
The third line turns off asynchronized loading, to make sure that the parser will
not continue execution before the document is fully loaded.
The fourth line tells the parser to load the XML document called note.xml.
Loading pure XML text into the parser
XML text can also be loaded from a text string.
The following code loads a text string into the XML parser:
<script type="text/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.
Displaying XML with JavaScript
To display XML you can use JavaScript.
JavaScript (or VBScript) can be used to import data from an XML file and
display the XML data inside an HTML page.
To
see how XML and HTML complement each other
this way; first look at the XML document (note.xml),
then open the HTML document (note.htm) that contains
a JavaScript which reads the XML file and displays
the information inside predefined spans in the HTML page.
To see how it works, Try
It Yourself
You can see a lot more of this kind of JavaScript in our DOM
School.
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|