MORE INFORMATION
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 & "\books.xml"
xsl.Load App.Path & "\booklisting.xsl"
xsl.setProperty "AllowDocumentFunction", False
Debug.Print xml.transformNode(xsl)
Books.xml
<?xml version="1.0" encoding="utf-8" ?>
<Books>
<Book>
<Title>XML Programming</Title>
<Author>1</Author>
</Book>
<Book>
<Title>XML Step by Step</Title>
<Author>2</Author>
</Book>
</Books>
Authors.xml
<?xml version="1.0" encoding="utf-8" ?>
<Authors>
<Author>
<Id>1</Id>
<Name>John</Name>
</Author>
<Author>
<Id>2</Id>
<Name>Peter</Name>
</Author>
</Authors>
BookListing.xsl
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books">
<HTML>
<BODY>
<H3>Book Listing</H3>
<TABLE BORDER="1">
<TR>
<TH>Title</TH>
<TH>Author</TH>
</TR>
<xsl:for-each select="Book">
<xsl:variable name="vId" select="Author"/>
<TR>
<TD>
<xsl:value-of select="Title"/>
</TD>
<TD>
<!-- Use the document() to retrieve the author's name from Authors.xml -->
<xsl:value-of select="document('Authors.xml')/Authors/Author[Id=$vId]/Name"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</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 "MaxXMLSize", 2
xml.Load "Data.xml"
If xml.parseError.errorCode <> 0 Then
Debug.Print xml.parseError.reason
Else
Debug.Print "Data loaded successfully"
End If
New SAX Properties and Features
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 "max-xml-size", 2
rdr.parseURL "c:\data.xml"
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="1.0"?>
<catalog xmlns="xsdcatalog" xsi:schemaLocation='xsdcatalog books.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<book id="bk101">
<author>
<FirstName>Matthew</FirstName>
<LastName>Gambardella</LastName>
</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with
XML.</description>
</book>
</catalog>
Books.xsd
<xs:schema targetNamespace="xsdcatalog" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="xsdcatalog" elementFormDefault="qualified">
<xs:element name="catalog" type="CatalogData"/>
<xs:complexType name="CatalogData">
<xs:sequence>
<xs:element name="book" type="bookdata" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bookdata">
<xs:sequence>
<xs:element name="author" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="genre" type="xs:string"/>
<xs:element name="price" type="xs:float"/>
<xs:element name="publish_date" type="xs:date"/>
<xs:element name="description" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</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 "schema-validation", True
rdr.putFeature "exhaustive-errors", True
rdr.putFeature "use-schema-location", False
Set rdr.errorHandler = Validator
rdr.parseURL App.Path & "\books.xml"
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 & " Line : " & oLocator.lineNumber
End Sub
Private Sub IVBSAXErrorHandler_fatalError(ByVal oLocator As MSXML2.IVBSAXLocator, strErrorMessage As String, ByVal nErrorCode As Long)
Debug.Print strErrorMessage & " Line : " & oLocator.lineNumber
End Sub
Private Sub IVBSAXErrorHandler_ignorableWarning(ByVal oLocator As MSXML2.IVBSAXLocator, strErrorMessage As String, ByVal nErrorCode As Long)
End Sub