Hi to all,
I've written a simple XML file and I'm trying to validate it using
XMLValidatingReader and ValidationEventHandler event.
This is my code:
Imports System.Xml
Imports System.Xml.Schema
Module Module1
Dim IsValid As Boolean = True
Sub main()
Dim filename As String = "Example.xml"
Dim TReader As New XmlTextReader(filename)
Dim VReader As XmlValidatingReader = New
XmlValidatingReader(TReader)
VReader.ValidationType = ValidationType.DTD
AddHandler VReader.ValidationEventHandler, AddressOf
myValidationEventHandler
While VReader.Read()
End While
TReader.Close()
VReader.Close()
MsgBox(IsValid.ToString)
End Sub
Private Sub myValidationEventHandler(ByVal Sender As Object, ByVal args
As ValidationEventArgs)
IsValid= False
End Sub
End Module
This is the file Example.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--DTD-->
<!DOCTYPE Books [
<!ELEMENT Books (Book)+>
<!ELEMENT Book (author, summary)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT summary (#PCDATA | %reference;)*>
<!ELEMENT ref (#PCDATA)>
<!ATTLIST Book
title CDATA #REQUIRED
<!--entities-->
<!ENTITY % reference "ref">
]>
<!--End Of DTD-->
<Books>
<Book title="The Hound of the Baskerville">
<author>Arthur Conan Doyle</author>
<summary>It's a tale of Sherlock Holmes by Sir <ref>Arthur Conan
Doyle</ref>, was first published in serial form in 1901, then in book form
in 1902. It's the story of an age-old curse and it's ramifications to the
Bakerville family. <ref>Sherlock Holmes</ref> and <ref>Dr. Watson</ref> are
on the case!</summary>
</Book>
<Book title="Murders on the Rue Morgue">
<author>Edgar Allan Poe</author>
<summary>In <ref>Poe</ref>'s "Murders on the Rue Morgue," his
fictional detective <ref>C. Auguste Dupin</ref>, together with Dupin's
friend and narrator, read in the newspaper of two particularly gruesome
murders.</summary>
</Book>
</Books>
This file is valid and my procedure's result is "True". But if you remove
the end tag </ref>, for example, the file will not be valid but my
procedure's result will be "True"!!!!
Why? Is it perhaps a bug? Has someone any ideas?
Thanks in advance,
Fede.