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 used in scripts orProgram. 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, use the followingCodeYou can create XML document objects:
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.