Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Problem with XML Validation against schema >Thread Next - Re: Problem with XML Validation against schema Re: Problem with XML Validation against schemaTo: NULL Date: 12/7/2006 1:36:00 PM espresso wrote: > I've written a method that checks it a XML file conforms to a specific > XML schema. One of my XML schemas is rather complex and involves > namespaces etc. > > Now I'm having the problem, that if I use my method with any general > XML file, that does not even has the right root element, it returns > true, which means the xml file conforms to that xsd. Bad problem :-( > When i check the XML file with XMLSpy (i have to assign the schema > first), XMLSpy says the XML file is not valid - of course. The problem is that in terms of XSD schema validation if the validator looks at the root element of your XML instance document that it decides based on the namespace of the element whether it has a schema to validate against or not. If it does not find a schema with the target namespace being the namespace of the root element then it only emits a warning but does not report a validation error. So set up a ValidationEventHandler and make sure you receive warnings, then check those warnings and you should get a warning in the handler if an XML document is being validated where the validator can't find a schema with a matching namespace. > XmlDocument xmlDoc = new XmlDocument (); Alternatively, if you use XmlDocument to load the XML, you can simply check whether xmlDoc.DocumentElement.NamespaceURI matches the schemas target namespace. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
