本文整理汇总了VB.NET中System.Xml.Schema.XmlSchemaCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlSchemaCollection.Add方法的具体用法?VB.NET XmlSchemaCollection.Add怎么用?VB.NET XmlSchemaCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Schema.XmlSchemaCollection 的用法示例。
在下文中一共展示了XmlSchemaCollection.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SchemaCollectionSample
Option Strict
Option Explicit
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Public Class SchemaCollectionSample
Private doc1 As String = "booksSchema.xml"
Private doc2 As String = "booksSchemaFail.xml"
Private doc3 As String = "newbooks.xml"
Private schema As String = "books.xsd"
Private schema1 As String = "schema1.xdr"
Private reader As XmlTextReader = Nothing
Private vreader As XmlValidatingReader = Nothing
Private m_success As Boolean = True
Public Sub New()
'Load the schema collection
Dim xsc As New XmlSchemaCollection()
xsc.Add("urn:bookstore-schema", schema) 'XSD schema
xsc.Add("urn:newbooks-schema", schema1) 'XDR schema
'Validate the files using schemas stored in the collection.
Validate(doc1, xsc) 'Should pass.
Validate(doc2, xsc) 'Should fail.
Validate(doc3, xsc) 'Should fail.
End Sub
Public Shared Sub Main()
Dim validation As New SchemaCollectionSample()
End Sub
Private Sub Validate(filename As String, xsc As XmlSchemaCollection)
m_success = True
Console.WriteLine()
Console.WriteLine("Validating XML file {0}...", filename.ToString())
reader = New XmlTextReader(filename)
'Create a validating reader.
vreader = New XmlValidatingReader(reader)
'Use the schemas stored in the schema collection.
vreader.Schemas.Add(xsc)
'Set the validation event handler.
AddHandler vreader.ValidationEventHandler, AddressOf ValidationCallBack
'Read and validate the XML data.
While vreader.Read()
End While
Console.WriteLine("Validation finished. Validation {0}", IIf(m_success, "successful", "failed"))
Console.WriteLine()
'Close the reader.
vreader.Close()
End Sub
Private Sub ValidationCallBack(sender As Object, args As ValidationEventArgs)
m_success = False
Console.Write((ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message))
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Xml.Schema,代码行数:69,代码来源:XmlSchemaCollection.Add
示例2: XmlSchemaCollection
Dim sc As XmlSchemaCollection = New XmlSchemaCollection()
AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack
' Create a resolver with the necessary credentials.
Dim resolver As XmlUrlResolver = New XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials
' Add the new schema to the collection.
sc.Add("", New XmlTextReader("sample.xsd"), resolver)
开发者ID:VB.NET开发者,项目名称:System.Xml.Schema,代码行数:9,代码来源:XmlSchemaCollection.Add
注:本文中的System.Xml.Schema.XmlSchemaCollection.Add方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论