Microsoft KB Archive/823594

= INFO: New DOM and SAX Properties and Features in MSXML 4.0 SP2 and MSXML 3.0 SP4 =

Article ID: 823594

Article Last Modified on 7/26/2003

-

APPLIES TO


 * Microsoft XML Parser 3.0
 * Microsoft XML Core Services 4.0

-



SUMMARY
This article documents the new DOM and SAX properties and features that are implemented in MSXML 4.0 Service Pack 2 (SP2) and MSXML 3.0 Service Pack 4 (SP4).



New DOM Properties
Note Use the setProperty DOM application programming interface (API) method to set the DOM properties that this section describes.

AllowDocumentFunction
Implemented by: MSXML 4.0 SP2 and MSXML 3.0 SP4

You can use the AllowDocumentFunction DOM property to disallow the use of the XSLT document function in XSLT transformations. This property must be set on the DOM object that is used to load the XSLT style sheet, and applies to all transformations that are executed by using the AllowDocumentFunction property. If this property is set to False, when you try to use the document function in XSLT transformations, the XSLT transformations fail, and you receive the following error message:

Access denied

This error message is raised only when the transformation is executed. When set to True, document references in the style sheet are resolved as described by the World Wide Web Consortium (W3C) XSLT specifications. The default value for this property is True. This property is not copied when a DOM object is cloned.

When you try to use the following MSXML code to execute an XSLT transformation by using the following sample data and style sheet files, you receive the following error message:

Access Denied

You receive the error message because the AllowDocumentFunction DOM property has been set to False on the DOM object where the style sheet is loaded.

The following Visual Basic code executes an XSLT transformation that uses the document function: Dim xml As DOMDocument40 Dim xsl As DOMDocument40

Set xml = New DOMDocument40 Set xsl = New DOMDocument40

xml.Load App.Path & &quot;\books.xml&quot; xsl.Load App.Path & &quot;\booklisting.xsl&quot;

xsl.setProperty &quot;AllowDocumentFunction&quot;, False

Debug.Print xml.transformNode(xsl)

Books.xml
   XML Programming 1   XML Step by Step 2  </Books>

Authors.xml
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>   <Id>1</Id> <Name>John</Name> </Author>  <Id>2</Id> <Name>Peter</Name> </Author> </Authors>

BookListing.xsl
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;Books&quot;> <HTML> <BODY>

<H3>Book Listing</H3> </BODY> </HTML> </xsl:template> </xsl:stylesheet>

MaxXMLSize Property
Implemented by: MSXML 4.0 SP2 and MSXML 3.0 SP4

You can use MaxXMLSize DOM property to limit the size of the XML data that can be loaded in a DOM instance. The value for this property is specified in kilobytes. An E_ABORT (operation aborted) load error is reported through the parseError property of the DOM object if you try to load XML data that is larger than the size that is defined by using this property.

The range of valid values for this property is from 0 to 2**22-1. The default value for this property is 0. A default value of 0 implies “unlimited”. When this property is not set, or is set to 0, data of any size (only constrained by the resources that are available on the system) can be loaded in the DOM object. This property is not copied when the DOM object is cloned.

In the following Visual Basic sample, if the size of the data.xml document that is loaded in the DOM object is greater than 2 KB (2048 bytes), you receive the following error message:

Operation aborted

Dim xml As DOMDocument40 Set xml = New DOMDocument40

'MaxXMLSize is defined as 2KB xml.setProperty &quot;MaxXMLSize&quot;, 2

xml.Load &quot;Data.xml&quot;

If xml.parseError.errorCode <> 0 Then Debug.Print xml.parseError.reason Else Debug.Print &quot;Data loaded successfully&quot; End If

Max-xml-size Property
Implemented by: MSXML 4.0 SP2 and MSXML 3.0 SP4

This is the SAX equivalent of the DOM MaxXMLSize property that is described earlier in the DOM properties section. Set the max-xml-size property by using the putProperty MSXML SAX Reader API method.

If you try to parse data (by using the parse or the parseURL SAX Reader methods) that is larger that the size that is defined by using this property, you receive the following error message:

c00cee01: Unexpected end of input

In the following Visual Basic sample, you receive this error message if the size of the data.xml document that is parsed by using the SAX Reader is greater than 2 KB (2048 bytes). Dim rdr As SAXXMLReader40 Set rdr = New SAXXMLReader40

'max-xml-size is defined as 2KB rdr.putProperty &quot;max-xml-size&quot;, 2 rdr.parseURL &quot;c:\data.xml&quot;

Use-schema-location Feature
Implemented by: MSXML 4.0 SP2

This feature is set by using the putFeature SAX Reader API method. You can use this method to specify whether the SAX Reader should resolve and use XML schemas that are referenced by an xsi:schemaLocation or an xsi:noNamespaceSchemaLocation attribute in an XML instance document to validate its data.

By default, this feature is enabled. This implies that a schema that is referenced in an XML instance document by using a schema location attribute will be used to validate its data. When set to False, the schema location attribute is ignored and treated as a regular XML attribute.

The setting for this feature is ignored when an XMLSchemaCache object is associated with a SAX Reader. In this case, the schema that is supplied by using the cache will be used to validate the data regardless of whether the use-schema-location feature is enabled.

The following sample XML file and XSD schema are used in this sample code. Notice that the XML document uses an xsi:schemaLocation attribute to reference the books.xsd schema, and that its data does not match the structure that is defined in the schema. (The FirstName and LastName child elements are not defined in the schema of the author element): <?xml version=&quot;1.0&quot;?> <catalog xmlns=&quot;xsdcatalog&quot; xsi:schemaLocation='xsdcatalog books.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> <book id=&quot;bk101&quot;> <FirstName>Matthew</FirstName> <LastName>Gambardella</LastName> XML Developer's Guide Computer 44.95      <publish_date>2000-10-01</publish_date> An in-depth look at creating applications with XML.

Books.xsd
<xs:schema targetNamespace=&quot;xsdcatalog&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;xsdcatalog&quot; elementFormDefault=&quot;qualified&quot;>

<xs:element name=&quot;catalog&quot; type=&quot;CatalogData&quot;/>

<xs:complexType name=&quot;CatalogData&quot;> <xs:sequence> <xs:element name=&quot;book&quot; type=&quot;bookdata&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xs:sequence> </xs:complexType>

<xs:complexType name=&quot;bookdata&quot;> <xs:sequence> <xs:element name=&quot;author&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;title&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;genre&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;price&quot; type=&quot;xs:float&quot;/> <xs:element name=&quot;publish_date&quot; type=&quot;xs:date&quot;/> <xs:element name=&quot;description&quot; type=&quot;xs:string&quot;/> </xs:sequence> <xs:attribute name=&quot;id&quot; type=&quot;xs:string&quot;/> </xs:complexType> </xs:schema> Using the following Visual Basic code to parse the sample XML data that is provided earlier, does not generate any validation error because the use-schema-location feature has been disabled. If this feature was enabled or not explicitly set, validation errors are reported to indicate that the FirstName and LastName elements in the data are not valid. Dim rdr As MSXML2.SAXXMLReader40 Set rdr = New MSXML2.SAXXMLReader40

Dim Validator As New SAXValidator

rdr.putFeature &quot;schema-validation&quot;, True rdr.putFeature &quot;exhaustive-errors&quot;, True rdr.putFeature &quot;use-schema-location&quot;, False

Set rdr.errorHandler = Validator

rdr.parseURL App.Path & &quot;\books.xml&quot;

Code in SAXValidator.cls
(The IVBSAXErrorHandler implementation that is used in the earlier sample.) Implements MSXML2.IVBSAXErrorHandler

Private Sub IVBSAXErrorHandler_error(ByVal oLocator As MSXML2.IVBSAXLocator, strErrorMessage As String, ByVal nErrorCode As Long) Debug.Print strErrorMessage & &quot; Line : &quot; & oLocator.lineNumber End Sub

Private Sub IVBSAXErrorHandler_fatalError(ByVal oLocator As MSXML2.IVBSAXLocator, strErrorMessage As String, ByVal nErrorCode As Long) Debug.Print strErrorMessage & &quot; Line : &quot; & oLocator.lineNumber End Sub

Private Sub IVBSAXErrorHandler_ignorableWarning(ByVal oLocator As MSXML2.IVBSAXLocator, strErrorMessage As String, ByVal nErrorCode As Long)

End Sub

Keywords: KB823594

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.