Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

XML and XSD in vb.net 2005

Last post 05-10-2008 6:16 AM by D'Scouser. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-25-2008 3:00 AM

    • yr
    • Top 500 Contributor
    • Joined on 06-01-2007
    • United States
    • Member
    • Points 370

    XML and XSD in vb.net 2005

     i am buildng an XML using xml writer in vb.net 2005 dynamically ,and also i am having  XSD file to validate generating xml file .I Want to attach  the XSD file  to the XML file dynamically.How can i do it ..If u have anyCode it will be very helpful for me

     

    Thanks,

    Yesu

    • Post Points: 10
  • 05-10-2008 6:16 AM In reply to

    • D'Scouser
    • Top 150 Contributor
    • Joined on 09-20-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,015

    Re: XML and XSD in vb.net 2005

    It seems strange to be dynamically creating the xml document, and to then add the schema. You will need to know the structure of the xml document before creating the document, which sort of destroys the point of a schema. I can only presume you will be adding the schema prior to compiling the xml file.

     Dim schema As New XmlSchemaSet()

    schema.Add("namespace", ".xsd")

    Dim settings As XmlReaderSettings = New XmlReaderSettings()

    settings.Schemas.Add(schema)

    settings.ValidationType = ValidationType.Schema

    Dim reader As XmlReader = XmlReader.Create(".xml", settings)

    You will probably be working with a stream, so just change the first parameter of the XmlReader.Create object. You could also raise a ValidationCallback on the XmlDocument class, if this is your preferred method for reading an Xml document. This follows on from above:

    Dim ev As New ValidationEventHandler(AddressOf ValidationCallback)Dim doc As New XmlDocument()

    doc.Load(reader)

    doc.Validate(ev)

    End Sub

    Protected Sub ValidationCallback(ByVal sender As Object, ByVal ev As ValidationEventArgs)

    If ev.Severity = XmlSeverityType.Error Then

    ' ... error handling here

    ElseIf ev.Severity = XmlSeverityType.Warning Then

    ' ... warning handling here.

    End If

    End Sub

    • Post Points: 5
Page 1 of 1 (2 items)