[jdom-interest] Configuring source of schema file when valida ting

Norrman Per per.norrman at canovia.se
Mon Oct 7 02:27:28 PDT 2002


 Hi,

here's a utility method I used in a recent project. The 
key here is the external.... property. You must of course find
a way to construct the absolute path to your schema--I used
ServletContext.getRealPath(..).


    public static SAXBuilder getValidatingSAXBuilder() 
       throws TMUIException
    {
        try
        {
            String sl = createSchemaLocation();
            SAXBuilder builder = new SAXBuilder(true);
            builder.setFeature(
               "http://apache.org/xml/features/validation/schema",   
                true);
            builder.setProperty(
 
"http://apache.org/xml/properties/schema/external-schemaLocation",
               sl);
            return builder;
        } catch (Exception e)
        {
            throw new TMUIException(e);
        }
    }
 

-----Original Message-----
From: Craig Dickson
To: 'jdom-interest at jdom.org'
Sent: 2002-10-05 00:28
Subject: [jdom-interest] Configuring source of schema file when validating

Hi,
 
My apologies if this has been asked on this list before. I had a look
through the archives but could not see anything on this exact topic.
Please direct me to the post if it has however and I just missed.
 
We have a set of EJB Session beans that process incoming request from
clients that are XML messages (it is not yet a full blown web service,
but hopefully someday it will be). The XML documents currently specify a
schema in their root node and validation seems to be operating quite
nicely.
 
The issue we have is that the paths specified to the schemas are in the
form "schemas/inboundCustomerOrder.xsd". We use a SAXBuilder to create
the document in memory and pass 'true' to the SAXBuilder constructor. We
then call SAXBuilder.build(...) passing a Reader in. Now it would appear
that the internal workings look for the schema by doing something like
'new File(schemaPath)' and then obviously create an InputStream of some
description and read the schema file. This forces (in our case) the
'schemas' directory to be in our Weblogic root, since this is where the
relative path is verified from. This is very unfriendly to our customers
and not exactly J2EE compliant.
 
What would like to be able to do is somehow package the schemas into our
.ear file so that it is all together and deployed all nicely. We can
probably figure out how to mount the schemas in the .ear file, but that
is pointless since there is no way (that we can see) to instruct the
parser where to load the schema from, or pass the schema as an
InputStream or anything like that. We have thought of maybe trying to
use a HTTP URL as the schema location, but we think this is a "fragile"
solution as it means our whole application is at the mercy of a lowly
web server - if it goes down we are in big trouble.
 
Anyone grasp what we are getting at? :)
 
Are missing something, or have we really hit a brick wall here?
 
Thanks in advance,
Craig
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.F-Secure.com/



More information about the jdom-interest mailing list