473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Validating against a custom schema

Bob Ross
119 100+
I am simply playing around with xml schemas to understand them better and came across this article -
http://msdn2.microsoft.com/en-us/library/as3tta56.aspx

The trouble is in this example no matter what changes I make to the XML document it never raises the validationEventHandler.

Here is my code -
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Shared Sub ValTest()
  3.             Dim sc As XmlSchemaSet = New XmlSchemaSet()
  4.  
  5.             ' Add the schema to the collection.
  6.             sc.Add("urn:bookstore-schema", System.Web.Hosting.HostingEnvironment.MapPath("~\UserConfigSchema.xsd"))
  7.  
  8.             ' Set the validation settings.
  9.             Dim settings As XmlReaderSettings = New XmlReaderSettings()
  10.             settings.ValidationType = ValidationType.Schema
  11.             settings.Schemas = sc
  12.             AddHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler
  13.  
  14.             ' Create the XmlReader object.
  15.             Dim reader As XmlReader = XmlReader.Create(System.Web.Hosting.HostingEnvironment.MapPath("~\Default Profiles\SE.xml"), settings)
  16.  
  17.             ' Parse the file. 
  18.             While reader.Read()
  19.             End While
  20.         End Sub
  21.  
  22.         Private Shared Sub ValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
  23.             'Just for testing
  24.             Dim obj = sender
  25.             Dim obj2 = args
  26.         End Sub
  27.  
The namespaces are correct and I can assure you that SE.xml should not validate against UserConfigSchema.xsd as I have thrown in some random new elements.

Can anyone point in the righ direction? What am I doing wrong?
Feb 22 '08 #1
1 879
Bob Ross
119 100+
Typical I spend ages trying to get this to work, fail, so post it on here and it works.
I tihnk all I needed to do was to remove the code from an existing sub and place in a new one. Which I did to make it readable on here and now it works.
Oh well.
Feb 22 '08 #2

Sign in to post your reply or Sign up for a free account.

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...
4
by: Jon Poploskie | last post by:
Hello, I have an xsd file that I'm trying to use to validate some xml against. I'm hoping this is a simple problem, but I just don't see it. I get the error "The 'role' element is not...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
1
by: Ryan | last post by:
I have a very complex XDR schema that uses namespaces: xmlns="urn:schemas-microsoft-com:xml-data" xmlns:b="urn:schemas-microsoft-com:BizTalkServer" xmlns:d="urn:schemas-microsoft-com:datatypes"...
3
by: AP | last post by:
Hello, I'm trying to use .NET to validate incoming XML documents against the appropriate schema in our database. I do not want to use the document's schemaLocation attribute to validate for...
1
by: Derek | last post by:
I am writing a web application for job seekers, and am adding a section that allows administrators to upload jobs to the system via xml. I have used an xml schema to validate the xml they upload....
2
by: Joakim Olesen | last post by:
Hello When validating xml against a schema, the most frequent error I get is something like "The 'FOO' attribute has an invalid value according to its data type. An error occurred at , (25,...
2
by: Ian | last post by:
I've inherited some xml that doesn't have a namespace and doesn't have a reference to the schema. The schema doesn't have a targetNamespace attribute. I'm trying to build a test tool, in C#, which...
2
by: mortb | last post by:
Why is line number and position = 0 in the code below? Valiation errors are found but not their position. cheers, mortb public static void Main() { XmlDocument xml = new XmlDocument();...
0
by: nmaddock | last post by:
Hi Guys, seen this example on msdn, how can i remove the invalide nodes and elements when they fail against the schema and then save to a new xml document. any help would be great my code is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.