當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET XmlSchemaCollection.Add方法代碼示例

本文整理匯總了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;未經允許,請勿轉載。