[jdom-interest] Schema validation.

Hans Prüller hans.prueller at igs.at
Wed Jan 16 04:18:50 PST 2002


Hi,

I've been using JDOM with schema validation for a while and it works
without setting features on the XMLReader.
The only problems I have is, that Xerces doesn't know the xsd:any - element
and throws exceptions in xsd:unique-expressions but
without them it works fine.

here's the way I do it:

//create a File-Object for SAXBuilder
xmlFile = new File(path_to_file);

if (xmlFile.exists())
{
     //create a SAXBuilder with VALIDATION
     SAXBuilder sax = new SAXBuilder(true);
     try
     {
          doc=sax.build(xmlFile);
     }
     catch (org.jdom.JDOMException e)
     {
          Logger.logEvent(e.getMessage());
          e.printStackTrace();
     }
}

The code segment above validates the xml-File against a schema and if the
file is valid, no exception occurs and
everything goes fine.

hans



                                                                                                                                                   
                    Damien Dudouit                                                                                                                 
                    <damien at ssl.co.uk>        An:     jdom-interest at jdom.org                                                                       
                    Gesendet von:             Kopie:                                                                                               
                    jdom-interest-admi        Thema:  [jdom-interest] Schema validation.                                                           
                    n at jdom.org                                                                                                                     
                                                                                                                                                   
                                                                                                                                                   
                    16.01.2002 12:35                                                                                                               
                                                                                                                                                   
                                                                                                                                                   



Hi,

I have been using JDom for a while and also received quite a few emails on
the mailing list with that title. But please don't hit the delete button
staightaway :).
So, today for the first time I tried validation on an XML schema. The
validation fails on the root element saying it must be defined. I'm using
JDom with Xerces and I went on Xerces web site to see how Xerces supports
XML Schema validation.
It appears it works by setting features on the XMLReader:
DTD validation:
reader.setFeature("http://xml.org/sax/features/validation", true)
XML Schema validation:
reader.setFeature("http://xml.org/sax/features/validation/schema", true)

I went on the code of JDom SAXBuilder and only the first feature for DTD
support is set. Since the org.jdom.SAXBuilder class only expose the method
setValidation(boolean) and not setFeature(..) on the underlying XMLReader,
what's the tip??

Thanks a lot,

Damien

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com





____________________________________________________
IGS Systemmanagement
GmbH & Co KG
Dorfplatz 5
A-4531 Piberbach
phone: +43 7228 6451 0       home: http://www.igs.at
fax: +43 7228 6451 30        eMail: igs at igs.at
hotline:
fax: +43 7228 6451 20        eMail: hotline at igs.at
____________________________________________________

NEWSFLASH___________________________________________

Detaillierte Informationen über das Anlagenmangement
sind ab sofort online verfügbar

Anlagenmanagement ab I.Quartal 2002 verfügbar
Demotermine ab sofort möglich
Reservierung unter: igs at igs.at

  näheres unter http://www.igs.at unter Downloads
NEWSFLASH___________________________________________




More information about the jdom-interest mailing list