Week 5 - MSXML - Martha's COIN 78b
CODES
Loading XML Document Transforming XML Document Writing Output to Page Using DOM Methods
Loading an XML Document
- Instantiate the XML parser using the ActiveXObject() function
xmldoc = new; ActiveXObject("Microsoft.XMLDOM"); - Set the async property on the object to false to ensure that the XML document is fully loaded before proceeding.
xmldoc.async = false;
- Load a specific XML document.
xmldoc.load("path/some.xml");
Transforming an XML Document with XSLT Stylesheet
output = xmldoc.transformNode(xsltstyle);
Writing Output to a Page
- Using document.write(). Place code in <SCRIPT/> block on page where you want output to appear.
document.write(output)
- Using outerHTML or innerHTML.
Create a "token" element (DIV ID="someToken") whose ourterHTML you'll set to output generated by XSL transformation. This will replace the DIV tag, while innerHTML inserts the output inside it.
someToken.innerHTML = output;
Using DOM Methods
- getElementsByTagName("tagName")
book_node = xmldoc.getElementsByTagName("book")[48] - setAttribute(name,value)
book_node.setAttribute('isbn','0735712867'); - getNamedItem(name)
attribute=book_node.attributes.getNamedItem("isbn");