HOW: ????? XML ????? ???? XML ?? Visual Basic .NET ?????? ?? ???

?????? ????????? ?????? ?????????
???? ???????: 317463 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ??? ????? ??????? XmlValidatingReader ??????? XMLSchemaCollection ?????? ?? ??? ??? ??? ??? ????? ??????? (XML) ?? ???? XML.

XmlValidatingReader ?????? ????? XmlReader ????? ??? ?????? ?? ??? ???????? XML. ????? ??????XmlValidatingReader ???? ?????? ??????? ?????? ?????? ?? XmlSchemaCollection. ???? ??????? ValidationType ?? XmlValidatingReader ??? ?????? ?? ????? ???? ??? ??????? ??????. ??? ??? ?????? ??????? ??? ValidationType.None ????? ???? nonvalidating.

????? ??? ????? ?????? ??? ????? ???? XML (XSD) ??????? ?????? XML "??????? ???????" (XDR) ??? XmlSchemaCollection. ??????? ??????? Add ?? ????? ??? URI ????? ????????. ?????? XML ?? ????? ????? ????????? URI ??????? targetNamespace ??????.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???:
  • Microsoft Visual Studio .NET ?????? ??? ???? ????? Microsoft Windows ??????
????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • Visual Basic .NET
  • ?????? XML ????????
  • ?????? XSD

????? ???? XSD

?? ???? ???????? ???????? ??????? ?? ??? ??? ???? ???? C:\Books.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:bookstore-schema" elementFormDefault="qualified" targetNamespace="urn:bookstore-schema">
	<xsd:element name="bookstore" type="bookstoreType" />
	<xsd:element name="comment" type="xsd:string" />
	<xsd:element name="author" type="authorName"/>
	<xsd:complexType name="authorName">
		<xsd:sequence>
			<xsd:element name="first-name" type="xsd:string" />
			<xsd:element name="last-name" type="xsd:string" />
		</xsd:sequence>
	</xsd:complexType>
	<xsd:complexType name="bookstoreType">
		<xsd:sequence maxOccurs="unbounded">
			<xsd:element name="book" type="bookType" />
			<xsd:element ref="comment" minOccurs="0" />
		</xsd:sequence>
	</xsd:complexType>
	<xsd:complexType name="bookType">
		<xsd:sequence>
			<xsd:element name="title" type="xsd:string" />
			<xsd:element ref="author" />
			<xsd:element name="price" type="xsd:decimal" />
		</xsd:sequence>
		<xsd:attribute name="genre" type="xsd:string" />
	</xsd:complexType>
	
</xsd:schema>
				

????? ????? .NET Visual Basic

  1. ????? Windows .NET Visual Basic ??????? ???????.
  2. ???? Button1 ??? Form1. ?? ???? ???????? ???????? ??????? ?????? ????? ??? ??? Form1 ???:
    Dim m_success As Boolean
    					
  3. ??? ??????? ?????? ??????? ?????? ValidationEventHandler ??? ????? ?????? ?? ????? ?? ???? XMLValidatingReader:
    Public Sub ValidationEventHandle(ByVal sender As Object, ByVal args As ValidationEventArgs)
            m_success = False
            Console.WriteLine((ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message))
        End Sub 'ValidationEventHandle
    						
    ??????: ??? ?? ????? ?? ????? ????? ???? ??????? ??? ????? ?????? ?? ????? ?? ?????? ??? ??????? (DTD) ? ?????? XML "??????? ???????" (XDR) ??????? ???? ????? (XSD) ????? ???? XML. ????? ??????? ????? ????? ?? ????? ValidationEventArgs ????? ??? ???????? ???????? ??? ?????.

    ???? ??????? ????? ?? ??????? ??????? ValidationEventArgs.Severity ???? ??? ????? ???? XML ?? ????. ??????? ??????? ????? ?? ??????? ??? ??? ?????? ?? ??? (??????? ????? XmlSeverityType.Error) ???? ???? ??? ??? ???? ??????? ????? (??????? ????? XmlSeverityType.Warning) ???? ???? ??? ?? ??????? ?????? ??? ?????.
  4. ?? ???? ???????? ???????? ??????? ?? ????? ????? Button1_Click:
            Dim reader As XmlValidatingReader = Nothing
            Dim myschema As New XmlSchemaCollection()
    
            Try
                'Create the XML fragment to be parsed.
                Dim xmlFrag As String = "<author  xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" & _
                                "<first-name>Herman</first-name>" & _
                               "<last-name>Melville</last-name>" & _
                             "</author>"
    
                'Create the XmlParserContext.
                Dim context As New XmlParserContext(Nothing, Nothing, "", XmlSpace.None)
               
                'Implement the reader. 
                reader = New XmlValidatingReader(xmlFrag, XmlNodeType.Element, context)
                'Add the schema.
                myschema.Add("urn:bookstore-schema", "Books.xsd")
    
                'Set the schema type and add the schema to the reader.
                reader.ValidationType = ValidationType.Schema
                reader.Schemas.Add(myschema)
    
                'Add the handler to raise the validation event.
                AddHandler reader.ValidationEventHandler, AddressOf Me.ValidationEventHandle
    
                While reader.Read
    
                End While
                Console.WriteLine("Completed validating xmlfragment")
    
            Catch XmlExp As XmlException
                Console.WriteLine(XmlExp.Message)
            Catch XmlSchExp As XmlSchemaException
                Console.WriteLine(XmlSchExp.Message)
            Catch GenExp As Exception
                Console.WriteLine(GenExp.Message)
            End Try
        End Sub
    					
  5. ??? ??? ??????? ??????? ?? ???? ??????? ??? XML ???? ????:
    Completed validating xmlfragment
    					
??????: ?????? XMLValidatingReader ??????? ?? ????? ??????? ?????? ?? ???? XML "?" ??????? ???. ????? ????? XML ??? ????? ????? ???? ??????. ?? ???? ????? ????? XML ??? XmlValidatingReader ?????? ??????? ??? ??? ?? ????? ????? XML ?????? ??????? ?????? ????? ?????? ?? ??????? ???????.

?????

?????? ??? ??????? ??????? ???? ??? ???? ????????? ????????? ??????? ?? "????? ??????? ?? Microsoft:
307379HOW TO: ?????? ?? ????? ??? ????? XML ?? ???? ??????? DTD ?? XDR XSD ?? Visual C# .NET
313826INFO: ??????? ?? ?????? XML ?? .NET Framework
313651INFO: ??????? XML ?? .NET Framework
?????? ??? ???? ?? ?????????? ???? MSDN ?????? ????? ???:
????? ????? System.Xml
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxml.asp

????? ????? ?? XML
http://msdn.microsoft.com/xml

???????

???? ???????: 317463 - ????? ??? ??????: 06/???/1424 - ??????: 2.2
????? ???
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
????? ??????: 
kbmt kbhowtomaster KB317463 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????317463

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com