Share via


writeAnnotation Method

 

[This feature was first implemented for MSXML 4.0.]

Writes a top-level annotation or an annotation for an XML Schema <element> declaration. The following objects can have annotations written to them: IXMLDOMDocument, IXMLDOMNode, IVBSAXContentHandler, and ISAXContentHandler. Any one of these four object types can be passed in the annotationSink parameter.

If the object passed in the annotationSink parameter is an IXMLDOMDocument (schema) object, the annotation for the item is written to the top-level <annotations> for the XML Schema. If a top-level annotation exists, an <annotations> root element is created, and all <annotation> declarations are located inside it.

For the other three object types, the <annotation> node of the object that is passed in is considered the root node. The DOMDocument will have the annotation node appended to the IXMLDOMnode.

Example

The po.xsd XML Schema that is referred to in these examples can be found in XML Schema Examples.

The following VBScript example shows how to write a top-level schema annotation into a DOM document.

Set oSchemaCache   = CreateObject("Msxml2.XMLSchemaCache.6.0")
Set oAnnotationDoc = CreateObject("Msxml2.DOMDocument.6.0")
oSchemaCache.add "http://tempuri.org/po.xsd", "po.xsd"
Set oSchema = oSchemaCache.getSchema("http://tempuri.org/po.xsd")
oSchema.writeAnnotation(oAnnotationDoc)
WScript.Echo oAnnotationDoc.documentElement.xml

The following VBScript example shows how to write an annotation for a schema item into a DOM document.

Set oSchemaCache   = CreateObject("Msxml2.XMLSchemaCache.6.0")
Set oAnnotationDoc = CreateObject("Msxml2.DOMDocument.6.0")
oSchemaCache.add "http://tempuri.org/po.xsd", "po.xsd"
Set oSchema = oSchemaCache.getSchema("http://tempuri.org/po.xsd")
Set ua = oSchema.types.itemByName("USAddress")
ua.writeAnnotation(oAnnotationDoc)
WScript.Echo oAnnotationDoc.documentElement.xml

JScript Syntax

var bolIsWritten = oISchemaItem.annotation(oAnnotationSink);  

Parameters

oAnnotationSink
An object. A pointer to the annotation target object. The following interfaces can be sent: IXMLDOMDocument, IXMLDOMNode, IVBSAXContentHandler, and ISAXContentHandler.

Return Values

bolIsWritten
A Boolean value. True if there is any annotation information for this schema item. False if there are no annotations for this schema item.

Visual Basic Syntax

bolIsWritten = oISchemaItem.annotation(oAnnotationSink);  

Parameters

oAnnotationSink
An object. A pointer to the annotation target object. The following interfaces can be sent: IXMLDOMDocument, IXMLDOMNode, IVBSAXContentHandler, and ISAXContentHandler.

Return Values

bolIsWritten
A Boolean value. True if there is any annotation information for this schema item. False if there are no annotations for this schema item.

C/C++ Syntax

HRESULT writeAnnotation(  
IUnknown* annotationSink,  
VARIANT_BOOL* isWritten  
);  

Parameters

annotationSink[in]
A pointer to the annotation target object. The following interfaces can be sent: IXMLDOMDocument, IXMLDOMNode, IVBSAXContentHandler, and ISAXContentHandler.

isWritten[out, retval]
A Boolean value. VARIANT_TRUE if there is any annotation information for this schema item. VARIANT_FALSE if there are no annotations for this schema item.

Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the annotationSink is not one of the following types: XMLDOMDocument, IXMLDOMNOde, IVBSAXContentHandler, or ISAXContentHandler.

E_POINTER
The value returned if the isWritten parameter is NULL.

E_FAIL
The value returned if something else is wrong.

Versioning

Implemented in: MSXML 4.0 and later

Applies to

ISchemaItem Interface

See Also

annotation Element