473,587 Members | 2,230 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
ValidationEvent Handle 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 ValidationEvent Handle(ByVal sender As Object, ByVal args As
ValidationEvent Args)
m_success = False
Console.WriteLi ne((ControlChar s.CrLf & ControlChars.Ta b &
"Validation error: " & args.Message))
End Sub 'ValidationEven tHandle

Dim reader As XmlValidatingRe ader = Nothing
Dim myschema As New XmlSchemaCollec tion()

Try
'Create the XML fragment to be parsed.
Dim xmlFrag As String = "<author xmlns='urn:book store-schema'
xmlns:xsi='http ://www.w3.org/2001/XMLSchema-instance'>" & _
"<first-name>Herman</first-name>" & _
"<last-name>Melville</last-name>" & _
"</author>"

'Create the XmlParserContex t.
Dim context As New XmlParserContex t(Nothing, Nothing, "",
XmlSpace.None)

'Implement the reader.
reader = New XmlValidatingRe ader(xmlFrag, XmlNodeType.Ele ment,
context)
'Add the schema.
myschema.Add("u rn:bookstore-schema", "Books.xsd" )

'Set the schema type and add the schema to the reader.
reader.Validati onType = ValidationType. Schema
reader.Schemas. Add(myschema)

'Add the handler to raise the validation event.
AddHandler reader.Validati onEventHandler, AddressOf
Me.ValidationEv entHandle

While reader.Read

End While
Console.WriteLi ne("Completed validating xmlfragment")

Catch XmlExp As XmlException
Console.WriteLi ne(XmlExp.Messa ge)
Catch XmlSchExp As XmlSchemaExcept ion
Console.WriteLi ne(XmlSchExp.Me ssage)
Catch GenExp As Exception
Console.WriteLi ne(GenExp.Messa ge)
End Try
End Sub
Jul 21 '05 #1
0 1333

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

Similar topics

9
12465
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 appreciated - it's proving very difficult to find. Failing that, does anyone know how to get the W3C's own online validating engine (XSV, I think it's...
1
1749
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
1438
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. But, the parser inside of Visual Studio seems to frequently validate against a cached version of the schema. Occassionally I have an XML file...
1
9100
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 way as I could come up with. Yes, it's obvious I don't know what I'm doing. I'm creating an XSD string and an XML string at runtime (ie: NOT read
6
4428
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 when they run the app? If so, what should I do if I can't guarantee that they will be? Can I bring all these files into the app? Is that desirable? ...
7
16233
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 instance for "05/07/1976" ,I need to make sure that it's in the right format ,It's not later than today and lots of other rules ,Is there somebody who can...
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 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...
2
1769
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. Thanks John
1
1580
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 use XMLValidatingReader to do the validation, without modifying either the schema or the instance? This is .NET framework 1.1.
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2347
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 we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.