You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Christian Nelson <cn...@slac.com> on 2003/04/10 20:04:44 UTC

Schema Related Questions

Hello Xerces World,

I've been using xerces for years to do simple XML parsing and it's
wonderful.  I recently started using it to build in-memory DOMs and
serialize them out as well... everything has been great.  I'm now starting
to use XML schemas, and well, things stopped being really easy. :)

Scouring the internet has made me feel like I'm not the only one who has
had some trouble dealing with schemas.  I tried trolling this mailing
list's archives, but they're down for some reason (or the xml.apache.org
website is incorrect).

I have several schema related questions.  I'm using Xerces 2.4.0 under
both Windows Xp and Red Hat Linux.

1) I've written a java application that uses XML as a load/save format.
To do this, I create a DOM in memory, and write it out.  No problems doing
this, it's been working great.  Now, what I'd like to do is specify what
schema it's supposed to adhere to.  Basically, I want to get this line to
happen:

<manufacturer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.some.biz/schemas/manufacturer.xsd">

Instead of this:

<manufacturer>

What API call(s) need(s) to be made to make this happen, and at what point
in the process of building the Document should I associate it with the
schema?

2) I read the Xerces FAQ, and I found out that you have a few hoops to
jump through to be able to do in-memory validation of a DOM Document
against a schema (Document.normalizeDocument()).  I built my new
dom3-xerces jars, did everything the FAQ mentioned, but every time I
execute my test app, as older version of xerces is found.  Presumably,
this is because Java 1.4 comes with its own.  I read how you can override
the JRE defaults by setting some application properties or somesuch.  I
stopped there.

I'm wondering what kind of experience people have had performing this
override, and if it messes things up with other java apps?  We use
Eclipse, JBoss, Tomcat, and a handful of other tools as well.

3) How else can I store schemas, other than placing schemas on a public
web site to be accessed by all?  I'd like to explore the option of keeping
them locally stored, without hard-coding a complete path to the schema.

Given:

<manufacturer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="manufacturer.xsd">

Is there a way to tell xerces where you keep your schemas so it can find
them, and not just look in the default location?  I'd like to have a
schemas directory as part of my application distribution.

Thanks in advance, and I apologize if these are common questions or out
of the scope of this mailing list.

Regards,
Christian

---------------------------------------------------------------------------
 Christian 'xian' Nelson                                  cnelson@slac.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Don't ask yourself what the world needs.  Ask yourself what makes
  you come alive, and go do that, because what the world needs is people
                  who have come alive." -- Howard Thurman
---------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Schema Related Questions

Posted by Christian Nelson <cn...@slac.com>.
Awesome, it does... :)

The divide between SAX and DOM <anything> is sometimes confusing to me.
Next time I'll just try it and see what happens.

Cheers!
Christian

On Thu, 17 Apr 2003, Jeff Greif wrote:

> DOMParser also uses EntityResolver.
> Jeff

---------------------------------------------------------------------------
 Christian 'xian' Nelson                                  cnelson@slac.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Don't ask yourself what the world needs.  Ask yourself what makes
  you come alive, and go do that, because what the world needs is people
                  who have come alive." -- Howard Thurman
---------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Schema Related Questions

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
DOMParser also uses EntityResolver.
Jeff
----- Original Message -----
From: "Christian Nelson" <cn...@slac.com>
To: <xe...@xml.apache.org>
Sent: Thursday, April 17, 2003 6:31 PM
Subject: Re: Schema Related Questions


>
> Thanks for the response!
>
> The second solution (EntityResolver) is only valid if I'm using a
> SAXParser, correct?  I'm actually using a DOMParser.  Is there an
> equivilent at this point?  My search yields that there is an experiemental
> version as part of the DOM 3 functionality.
>
> Thanks!
> Christian
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Schema Related Questions

Posted by Christian Nelson <cn...@slac.com>.
Thanks for the response!

The second solution (EntityResolver) is only valid if I'm using a
SAXParser, correct?  I'm actually using a DOMParser.  Is there an
equivilent at this point?  My search yields that there is an experiemental
version as part of the DOM 3 functionality.

Thanks!
Christian

> > 3) How else can I store schemas, other than placing schemas on a public
> > web site to be accessed by all?  I'd like to explore the option of keeping
> > them locally stored, without hard-coding a complete path to the schema.
> >
>
> You can specify/override which schema to use progmatically.  IE:
> static string EXTERNAL_SCHEMA_PROPERTY =
> "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
> XMLReader xr = new SAXParser();
> xr.setProperty(EXTERNAL_SCHEMA_PROPERTY, "/path/to/schema");
>
> You can use an entity resolver to "find" the schema for you:
> public class MyEntityResolver implements EntityResolver
> {
>     public InputSource resolveEntity(String publicID, String systemID)
> throws SAXException{
>         if (systemID.toLowerCase().endsWith(".xsd")){
>             // Return local copy of the copyright.xml file
>             String target = "/home/richard/dev/import_spec/" + systemID;
>             return new InputSource( target );
>         }
>         // If no match, returning null makes process continue normally
>         return null;
>     }
> }
>
> XMLReader xr = new SAXParser();
> xr.setEntityResolver(new MyEntityResolver());
>
> My problem with the above approach is that my schema has several files
> in it.  The entity resolver is only called once for the "top" level .xsd
> file. The parser then tries to find the other .xsd files which are
> included from the top level schema in the current working directory
> (which fails).  I asked about this behaviour about a week ago on the
> list and got no response, hopefully you will fair better.
>
> --
> Richard Rowell <ri...@bowmansystems.com>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>

---------------------------------------------------------------------------
 Christian 'xian' Nelson                                  cnelson@slac.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Don't ask yourself what the world needs.  Ask yourself what makes
  you come alive, and go do that, because what the world needs is people
                  who have come alive." -- Howard Thurman
---------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Schema Related Questions

Posted by Richard Rowell <ri...@bowmansystems.com>.
On Thu, 2003-04-10 at 13:04, Christian Nelson wrote:

> 3) How else can I store schemas, other than placing schemas on a public
> web site to be accessed by all?  I'd like to explore the option of keeping
> them locally stored, without hard-coding a complete path to the schema.
> 

You can specify/override which schema to use progmatically.  IE:
static string EXTERNAL_SCHEMA_PROPERTY =
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
XMLReader xr = new SAXParser();
xr.setProperty(EXTERNAL_SCHEMA_PROPERTY, "/path/to/schema");

You can use an entity resolver to "find" the schema for you:
public class MyEntityResolver implements EntityResolver 
{
    public InputSource resolveEntity(String publicID, String systemID)
throws SAXException{
        if (systemID.toLowerCase().endsWith(".xsd")){
            // Return local copy of the copyright.xml file
            String target = "/home/richard/dev/import_spec/" + systemID;
            return new InputSource( target );
        }
        // If no match, returning null makes process continue normally
        return null;
    }
}

XMLReader xr = new SAXParser();
xr.setEntityResolver(new MyEntityResolver());

My problem with the above approach is that my schema has several files
in it.  The entity resolver is only called once for the "top" level .xsd
file. The parser then tries to find the other .xsd files which are
included from the top level schema in the current working directory
(which fails).  I asked about this behaviour about a week ago on the
list and got no response, hopefully you will fair better.

-- 
Richard Rowell <ri...@bowmansystems.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org