Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: BUG: The minLength attribute in an XML Schema is not validated

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent