[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

xml schemas

Does anyone have sanple vb .net code for validating an xml file against its schema
0
davoman
Asked:
davoman
  • 2
1 Solution
 
armoghanCommented:
0
 
armoghanCommented:
0
 
iboutchkineCommented:
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”)
vr.Schemas.Add(Schemas)
‘ Read through the document.
Do While vr.Read()
‘ Process document here.
‘ If an error is found, an exception will be thrown.
Loop
vr.Close()
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now