You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Irene Levina <ir...@progress.com> on 2000/10/06 16:48:47 UTC

Validation and RevalidatingDOMParser questions

Folks:
I'm working on a project that use XML document as the configuration file
that can be customized by customers. Therefore we would like to use
validation feature to validate configuration data entered by customer.
So far I can not get it to work. Any help or suggestion what I'm doing
wrong would be appreciated.

First Question:
///////////////////////////////////////////////////
According Xerces documentation to turn on a   validation you  have to
use method setFeature() :
                p.setFeature("http://xml.org/sax/features/validation",
true);

So, I tried this with very simple XML file and external DTD:

XML file (bridge.xml):

     <?xml version='1.0'?>
     <!DOCTYPE bridgeDescriptor SYSTEM "bridgedescriptor.dtd" >
     <bridgeDescriptor>
     <bridge
         name = "bridgeName"
         class = "bridgeClassName"
         start = "ONCREATION">
         <resourceRef name = "SampleQ1" type = "destination" />
         <resourceRef name = "SampleQ2" type = "destination" />
     </bridge>
   </bridgeDescriptor>

DTD  (bridgedescriptor.dtd):

    <!ELEMENT bridgeDescriptor (bridge+)>
    <!ELEMENT bridge (resourceRef*)>
        <!ATTLIST bridge
        name CDATA #REQUIRED
        class CDATA #REQUIRED
         start (ONCREATION | LATER) #REQUIRED>

As you can see that all attributes are required for element bridge.
Thus I was expecting , that parser will generate an error if it will
parse bridge.xml where one of attribute is not specified, such as in the
followed sample name attribute is missing:

     <?xml version='1.0'?>
     <!DOCTYPE bridgeDescriptor SYSTEM "bridgedescriptor.dtd" >
     <bridgeDescriptor>
     <bridge
         class = "bridgeClassName"
         start = "ONCREATION">
         <resourceRef name = "SampleQ1" type = "destination" />
         <resourceRef name = "SampleQ2" type = "destination" />
     </bridge>
   </bridgeDescriptor>
     The following  code used to create DOM Parser and turn on
validation:

             DOMParser parser = new DOMParser();
             try{
                   parser.setFeature(
"http://xml.org/sax/features/validation", true);
                   parser.parse("bridge.xml");
             }
             catch(Exception e){ // }

     What I'm doing wrong that parser doesn't generate an error when it
supposed to ????
     (Tried  two version of xerces parser 1.0.3 and 1.2.0 result is same
, seems that validation doesn't work)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     Second question:
     Xerces documentation 1.0.3  and 1.2.0 listed RevalidatingDOMParser
class that can be  used to
     validate DOM nodes that has been read by parser. But ... xerces.jar
(in two versions 1.0.3 and
     1.2.0)doesn't contain this class. Is any tryed to use this class
????

     Thanks in advance for any help or suggestion provided.

     Irene Levina.