Community discussion forum

XML and XSD in vb.net 2005

  • 7 months ago

     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

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 months ago

    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 a reply

Enter your message below

Sign in or Join us (it's free).