Wiley Professional SQL Server 2005 XML 978-0-7645-9792-3 사용자 설명서

제품 코드
978-0-7645-9792-3
다운로드
페이지 12
XML Schema Validation
There is one major reason why XML Schema validation performance has improved, and that is type sup-
port. Type support will be defined in more detail in the next section; however, for XML Schema valida-
tion, type support comes into play in a huge way when you try to load or transform an XML document.
When an XML document is loaded into a reader and a schema applied to it, CLR types are used to store
the XML. This is useful because xs:long is now stored as a CLR long. First, the XML stores better this
way. Second, there’s no more of this useless untyped string stuff.
Type support also applies when creating an 
XPathDocument
by applying XSLT to an original
XPathDocument
. In this scenario, the types are passed from one document to another without having to
copy to an untyped string and then reparse them back the original type. This in itself is a tremendous
performance boost, especially when linking multiple XML components.
Conversion between schema types and CLR types was possible in version 1.1 using the 
XmlConverter
helper class, but conversion support is now extended to any 
XmlReader
XmlWrite
, and
XPathNavigator
class, discussed in the next section.
Type Suppor t
While XQuery support has been removed from version 2.0 of the .NET Framework, type support for
many of the XML classes now offers type conversions. Classes such as the 
XmlReader
XmlWrite
and 
XPathNavigator
are all now type-aware, and support conversion between CLR types and XML
schema types.
In version 1.0 of the .NET Framework, type conversion was done by using the 
xmlConvert
method,
which enabled the conversion of a schema data type to a CLR (or .NET Framework) data type.
For example, the following code demonstrates how to convert an 
xml
string value to a CLR Double data
type using the 
XmlConvert
in version 1.0 of the .NET Framework:
Imports System.Xml
‘declare local variables
Dim xtr As XmlTextReader = New XmlTextReader(“c:\testxml.xml”)
Dim SupplierID As Integer
‘loop through the xml file
Do While xtr.Read()
If xtr.NodeType = XmlNodeType.Element Then
Select Case xtr.Name
Case “SupplierID”
SupplierID = XmlConvert.ToInt32(xtr.ReadInnerXml())
End Select
End If
Loop
6
Chapter 1
05_597922 ch01.qxp  12/3/05  12:26 AM  Page 6