none
different validation exception with dtd vs. schema RRS feed

  • Question

  •  

    I am experiencing that using xmlreader to validate an xml document, I get an xmlschemavalidationexception when validating against a schema, but an xmlschemaexception when validating against a dtd. The specific case involved an xml file with an element having a missing attribute that is required by the dtd and schema, both of which are external to the xml document. If the attribute is put back in, then both validate OK. for the dtd, I set the prohibitdtd setting to false. If an entire element that is required is missing in the xml, then I get the same xmlschemavalidationexception when validating with the dtd and the schema. Anyone know what is going on in the case of the missing attribute?

     

    Bill

     

    Friday, December 5, 2008 9:39 PM

Answers

  • XmlSchemaValidationException derives from XmlSchemaException. So if you need to catch both it is enough to catch XmlSchemaException.

     

    Hope this helps.

    Pawel

    Saturday, December 6, 2008 3:18 AM
    Moderator
  • If a DTD defines a required attribute and the attribute is missing in the XML instance document then that is a validation error.

    What kind of errors are you looking for in the DTD, can you give an example?

    Saturday, December 6, 2008 3:54 PM
  • I am not validating when the file is first read. What I did not realize was that  if the dtd file itself has an error, it will be caught with an xmlException when first read. Therefore, once it is successfully read, I can invoke my validation routine and when the XmlSchemaException is fired I know that the xml file is not valid. In my earlier post I was asking how I would know if it is a problem with the dtd vs. the xml, but now I know. I was also a bit confused by the fact that a validation error based on a dtd throws

    an XmlSchemaException  while with a schema it throws a XmlSchemaValidationException. but at this point that is not relevant. I just catch both and need not be concerned about why.

     

    thanks for the input.

     

    Bill

    Saturday, December 6, 2008 9:53 PM

All replies

  • XmlSchemaValidationException derives from XmlSchemaException. So if you need to catch both it is enough to catch XmlSchemaException.

     

    Hope this helps.

    Pawel

    Saturday, December 6, 2008 3:18 AM
    Moderator
  • So how can I programatically distinguish between an error in the dtd and and a validation error, e.g., a missing attribute required by the dtd. From what  I have seen, xmlreader makes no such distinction in the case of a dtd.

     

    Bill

    Saturday, December 6, 2008 2:54 PM
  • If a DTD defines a required attribute and the attribute is missing in the XML instance document then that is a validation error.

    What kind of errors are you looking for in the DTD, can you give an example?

    Saturday, December 6, 2008 3:54 PM
  • I am not validating when the file is first read. What I did not realize was that  if the dtd file itself has an error, it will be caught with an xmlException when first read. Therefore, once it is successfully read, I can invoke my validation routine and when the XmlSchemaException is fired I know that the xml file is not valid. In my earlier post I was asking how I would know if it is a problem with the dtd vs. the xml, but now I know. I was also a bit confused by the fact that a validation error based on a dtd throws

    an XmlSchemaException  while with a schema it throws a XmlSchemaValidationException. but at this point that is not relevant. I just catch both and need not be concerned about why.

     

    thanks for the input.

     

    Bill

    Saturday, December 6, 2008 9:53 PM