473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ 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 1320

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

Similar topics

9
12441
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
1732
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
1428
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
9081
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
4416
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
16212
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
270
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
1763
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
1572
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
7125
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
7002
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
7205
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
7379
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...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.