po3.vbs Step-by-Step
This topic walks you through the Locate Declarations application. The code is interspersed with textual comments that describe each step of the application.
Click here for the Uncommented Code for the Write Annotations Application.
The Application
The code begins by creating objects to write the annotations to. For more information about these objects, see IXMLDOMSchemaCollection/XMLSchemaCache, IXMLDOMDocument/DOMDocument, and MXXMLWriter CoClass.
Set oSchemaCache = CreateObject("Msxml2.XMLSchemaCache.5.0") Set oAnnotationDoc = CreateObject("Msxml2.DOMDocument.5.0") Set writer = CreateObject("Msxml2.MXXMLWriter.5.0") writer.output=""
Add the XML Schema document to the schema cache, using its add
method. A SOM schema object is returned. The code now uses SOM interfaces to explore the schema object.
For more information about the schema cache, see the sections about the IXMLDOMSchemaCollection
add and get methods.
nsTarget="http://www.example.microsoft.com/po" oSchemaCache.add nsTarget, "po3.xsd" Set oSchema = oSchemaCache.getSchema(nsTarget)
Write top-level XML Schema annotations into a DOM document.
oSchema.writeAnnotation(oAnnotationDoc) WScript.Echo oAnnotationDoc.documentElement.xml
Write top-level XML Schema annotations into a DOM document node.
Set oAnnotationDoc.documentElement = oAnnotationDoc.createElement("root") oSchema.writeAnnotation(oAnnotationDoc.documentElement) WScript.Echo oAnnotationDoc.documentElement.xml
Write top-level XML Schema annotations into a SAX writer node.
oSchema.writeAnnotation(writer) WScript.Echo writer.output
Write annotations for an XML Schema element into a DOM Document.
Set ua = oSchema.types.itemByName("USAddress") Set oAnnotationDoc.documentElement = oAnnotationDoc.createElement("root") ua.writeAnnotation(oAnnotationDoc) WScript.Echo oAnnotationDoc.documentElement.xml
Write annotations for an XML Schema element into a DOM Document element.
ua.writeAnnotation(oAnnotationDoc.documentElement) WScript.Echo oAnnotationDoc.documentElement.xml