Accessing XML Documents Using DOM: Objectives
Accessing XML Documents Using DOM: Objectives
Objectives
In this lesson, you will learn to:
☛ Use XML DOM objects to perform the following tasks:
✓ Validate an XML document against an XML
schema
✓ Provide user-selected view of data stored in an
XML document
Task List
☛ Identify a mechanism to validate an XML document
against a schema.
☛ Identify the objects required to access an XML
document through a scripting language.
☛ Write the code to validate an XML document against
the schema.
☛ Execute the code.
addCollection(XMLSchemaColle This method adds schemas from other schema collections. It also
ction object) ensures that the namespaceURIs of the different schemas do not
clash.
get(namespaceURI) This method returns a node that contains the <schema> element.
namespaceURI(index number) This method returns the namespace that is associated with the
specified index number.
Just a Minute…
Write the code to add an XML schema called
“Products.xsd” to a schema collection.
Task List
☛ Identify a mechanism to access an XML document
programmatically.
☛ Identify the objects required to apply the style sheet to
the XML document during runtime.
☛ Create the XML document.
☛ Create the style sheets.
☛ Write the code to apply a style sheet dynamically to
an XML document.
☛ Execute the code.
Just a Minute…
The following JavaScript code is used to create
XSLTemplate and DOMDocument objects. Identify the
errors in the code, if any.
custss= new
activexObject(MSXML.XSLTemplate.4)
custdomdoc= activexobject(
"MSXML.ThreadedDOMdocument.4.0);
Just a Minute…
Identify the errors in the following JavaScript code:
xslProcObject.output=xmlDocObject;
xslProcObject.Transform
alert("xslProcObject");
Summary
In this lesson, you learned that:
☛ The XMLSchemaCache object is used to associate an
XML document with an XSD document.
☛ The XMLSchemaCache object is used to hold a collection
of schema documents that specify the rules to which XML
documents must conform.
☛ The XSLTemplate object is used to contain a compiled
XSL document.
☛ The XSLProcessor object is used to apply style sheets on
a given XML document.
Summary (Contd.)
☛ The XSLProcessor object is created using the
createProcessor() method.
☛ The XSLProcessor object is associated with an XML
document by using the input property of the XSLProcessor
object.
☛ The XSLProcessor object provides the transform() method
to transform an XML document according to the
information provided in an XSLT style sheet.