The XML Parser can read, update, create, and operate an XML document.
Use XML Parser
Microsoft's XML parser is bundled with ie5.0 + browser.
Once ie5.0 is installed, the XML parser is obtained. In addition to being called by the browser, this browser can also be called in scripts or programs. This parser supports programming models unrelated to programming languages and supports the following technologies:
- Javascript, VBScript, Perl, VB, Java, C ++, etc.
- W3C XML 1.0 and XML DOM
- DTD and XML document verification
If the browser uses JavaScript as the scripting language, you can use the following code to create an XML document object:
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM") |
If the browser uses VBScript as the script language, you can use the following code to create an XML document object:
set xmlDoc=CreateObject("Microsoft.XMLDOM") |
If you use the VBScript language in an ASP program, you can use the following code:
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") |
Load the XML document into the parser
You can use the script code to load the XML document into the parser.
The following code loads an XML document into the 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 of code creates an instance of the Microsoft XML parser.
The third line of code disables asynchronous loading to ensure that the XML parser does not parse the XML file before fully loading the XML file.
The fourth line tells the parser that the name of the XML document to be loaded is note. xml.
Load pure XML documents into the parser by characters
The parser can load XML text from a text string.
The following code loads a text string into the Parser:
<script type="text/javascript"> var text="<note>" text=text+"<to>Tove</to><from>Jani</from>" text=text+" |
Note that the "loadxml ()" method is used to load strings (instead of the "load ()" method used previously). "loadxml ()" is used to load strings, "load ()" is used to load XML documents.
Display XML data in Javascript
You can use JavaScript to display XML data.
JavaScript (or VBScript) can import data from XML documents and display the data on the HTML page.