Share via


getDeclaration Method

 

Returns an ISchemaItem object. This object is the declaration of the DOM node that is sent to the function. The declaration specifies the schema information that is used to validate the document item in the DOM node. The getDeclaration method also includes the declarations of XML schemas used by the associated document. This provides access to XML schemas loaded using xsi:schemaLocation, as well as XML schemas loaded from a schema cache object. The ISchemaItem interface can be used to obtain further information about the schema declaration stored in the ISchemaItem object.

JScript Syntax

var oSchemaItem = oDom.namespaces.getDeclaration(oDOMNode);  

Parameters

oDOMNode
An object. The DOM node for which a declaration object will be returned.

Return Values

oSchemaItem
An object. The schema item object that describes the specified DOM node, passed in the node parameter.

Example

The following JScript example shows the getDeclaration method in a schema.

// Load the XML document.  
var xmldoc = new ActiveXObject("MSXML2.DOMDocument.6.0");  
xmldoc.async = false;  
xmldoc.validateOnParse = false;  
xmldoc.load("doc.xml");  
xmldoc.setProperty("SelectionLanguage", "XPath");  
  
if (xmldoc.parseError.errorCode != 0){  
   var myErr = xmldoc.parseError;  
   WScript.Echo("You have error " & myErr.reason);  
} else {  
   // Retrieve the namespace URI for schema   
   // used in XML document.  
   var oDecl = xmldoc.namespaces.getDeclaration(xmldoc.documentElement);  
   WScript.Echo(oDecl.namespaceURI);  
}  
  

Resource Files

The JScript and example uses the following files.

doc.xml

<?xml version="1.0"?>
<x:doc  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:x='http://xsdtesting'
    xsi:schemaLocation='http://xsdtesting doc.xsd'>
   <x:notDeclared/>
</x:doc>

doc.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace = "http://xsdtesting"
    xmlns:x = "http://xsdtesting"
    elementFormDefault = "qualified">
   <xs:element name="doc"></xs:element>
</xs:schema>

Output

When used with the sample XML (doc.xml) and schema file (doc.xsd) files above, the examples in this topic return the namespace URI for the schema declared in doc.xml:

http://xsdtesting

C/C++ Syntax

HRESULT getDeclaration(IXMLDOMNode* node, ISchemaItem** item);  

Parameters

node [in]
An object. The DOM node.

item [out,retval]
An object. The schema object for the specified DOM.

Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the DOM node points to some object other than a Node or NULL.

E_POINTER
The value returned if the item object is NULL

E_FAIL
The value returned if the node does not have a corresponding declaration in the schema.

Note

The syntax oSchemaCollection.getDeclaration(oDOMNODE) is no longer supported and will return E_NOTIMPL.

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

Applies to

IXMLDOMSchemaCollection2-XMLDOMSchemaCollection

See Also

IXMLDOMNode