xml schemas

Posted on 2004-11-30
Last Modified: 2013-11-19
Does anyone have sanple vb .net code for validating an xml file against its schema
Question by:davoman
    LVL 18

    Expert Comment

    LVL 18

    Expert Comment

    LVL 28

    Accepted Solution

    Validating an XML File
    Before using XSD schemas, you need to import the namespace System.Xml.Schema
    namespace, which contains types like XmlSchema and XmlSchemaCollection.

    Imports System.Xml.Schema
    The code snippet that follows shows how you can create an XmlValidatingReader
    that uses the SuperProProductList.xsd file, and use it to verify that the XML in Super-
    ProProductList.xml is valid.

    ‘ Open the XML file.
    Dim fs As New FileStream(Request.ApplicationPath & _
    “\SuperProProductList.xml”, FileMode.Open)
    Dim r As New XmlTextReader(fs)
    ‘ Create the validating reader.
    Dim vr As New XmlValidatingReader(r)
    vr.ValidationType = ValidationType.Schema
    ‘ Add the XSD file to the validator.
    Dim Schemas As New XmlSchemaCollection()
    Schemas.Add(“SuperProProductList”, _
    Request.ApplicationPath & “\SuperProProductList.xsd”)
    ‘ Read through the document.
    Do While vr.Read()
    ‘ Process document here.
    ‘ If an error is found, an exception will be thrown.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now