473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validate XML Fragments Against an XML Schema in VB

MG
The following below is Microsoft sample to validate a XML document. My
question is how can I put the validate errors in DataGrid? Using the
ValidationEventHandle subroutine and adding ListBox control in that event
works find but i can't firgure out to use a DataGrid instead. Can someone
help, Please.?

Dim m_success As Boolean

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

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
Jul 21 '05 #1
0 1318

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Leona | last post by:
Hello all, does anyone know of a tool, preferably free, preferably on linux, which will take an xml file and validate it against your own custom W3C XML Schema file (.xsd) ?? All help...
1
by: QuantDev | last post by:
Hi NG, I would need to validate an XML fragment against a type defined within an XSD (which defines many other things). What is the correct way of achieving this? QD2004
1
by: Ron Rohrssen | last post by:
I've been working on learning XML schemas and trying to make use of the MS classes for validating data against a schema. So, I've been trying to work through some simple schemas and instances....
1
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
6
by: LesleyW | last post by:
Hi Apologies if this is a really dumb question, but being new to XML and Schemas, I wonder if giving the namespace for eg xsd or xsi as a website address means that the user has to be online...
7
by: Ali-R | last post by:
Hi all, I am getting a CSV file like this from our client: "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate **each filed value** against a set of rules ,for...
0
by: MG | last post by:
The following below is Microsoft sample to validate a XML document. My question is how can I put the validate errors in DataGrid? Using the ValidationEventHandle subroutine and adding ListBox...
2
by: John H | last post by:
Hi, How can i just use the XmlDocument object to validate an xml instanace against a schema referenced inside the xml instance? The Load method seems to not validate it against the schema. ...
1
by: JoeZ | last post by:
Hi all, I am using XMLValidatingReader to validate an xml instance against the xml schema. Currently the schema has the targetnamespace, but the instance doesn't have a namespace. Can I still...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.