Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: BUG: The minLength attribute in an XML Schema is not validated >Thread Next - Re: BUG: The minLength attribute in an XML Schema is not validated Re: BUG: The minLength attribute in an XML Schema is not validatedTo: NULL Date: 10/30/2008 5:17:00 PM TimB wrote:
> Thank you. I am doing wc3 validation though a little differently than your
> sample.
> Below is some VB.Net code I used to test with. "Try1" is using your method
> as close as I could translate it to VB. "Try1" has the same results as your
> test. "Try2" is how I was doing validation. I start with a loaded
> XmlDocument (received via messaging) rather than from a file in the file
> system. To get the XML into the XmlReader I first save it to a memory
> stream and then create the XmlReader with the content of the memory stream.
> "Try2" does not pick up the validation error on the foo element. "Try3" is
> using my method but with the IgnoreWhitespace XMLReaderSetting set to true.
> "Try3" does pick up both validation errors. Something about saving the
> XmlDocument to a memory stream and then creating the XmlReader from that
> stream must change the white space in the document.
>
> This seems to have changed at the time I installed the .Net Framework
> version 3.5 (Sp1). I mistakenly believed the problem was caused by the bug
> identified in article 826753. Knowing that wasn't the case helped a great
> deal!
If you have an XmlDocument and want to validate it then since .NET 2.0
you have a Validate method
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.validate.aspx
that you can use:
Dim doc As New XmlDocument()
doc.LoadXml("<root>...</root>")
doc.Schemas.Add(Nothing, "someSchemas.xsd")
doc.Validate(new ValidationEventHandler(AddressOf
someValidationEventHandler)
So there is no need to serialize to a MemoryStream and then create a
reader over that memory stream. But if you want to do that then you can
but you should ditch the XmlTextReader:
> Sub try2(ByVal aobjXMLDoc As XmlDocument)
> 'Validate an xml document. XML Document is alread loaded into an
> XmlDocument object.
>
> System.Console.WriteLine("Try2")
> Dim objXMLReaderSettigns As XmlReaderSettings = New XmlReaderSettings
> objXMLReaderSettigns.ValidationType = ValidationType.Schema
> objXMLReaderSettigns.Schemas.Add(Nothing, "c:\temp\xmlschema1.xsd")
> AddHandler objXMLReaderSettigns.ValidationEventHandler, AddressOf
> ValidationCallBack
>
> Dim objMemoryStrm As System.IO.Stream = New System.IO.MemoryStream
> aobjXMLDoc.Save(objMemoryStrm)
> objMemoryStrm.Position = 0
Remove the following line
> Dim objTextReader As XmlTextReader = New XmlTextReader(objMemoryStrm)
then simply do
Dim objXMLReader As XmlReader = XmlReader.Create(objMemoryStrm,
objXMLReaderSettigns)
that should fix the problem I think.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
