*
The moose likes XML and Related Technologies and the fly likes schema validation/parser problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "schema validation/parser problem" Watch "schema validation/parser problem" New topic
Author

schema validation/parser problem

Eugene Yusim
Greenhorn

Joined: Feb 13, 2004
Posts: 4
I am using the xerces 2.5 java parser to do schema validation and have
run into a problem that I am not sure if it's with my schema or the
parser.
The problem is this:
I have a base schema (base.xsd) and I extend it with a (extension.xsd)
which defines a new complex type by extending one of the types defined
in the base.xsd. ( I use "<xs:import>" since the extension.xsd has a different target namespace)
An instance document using the base.xsd:
<base:RootMsg xmlns:base="http://www.foo.com/base"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.foo.com/base base.xsd"
language="en-us">
....
</base:RootMsg>
validates just fine.
But when I create an instance document using extension.xsd:
<base:RootMsg xmlns:base="http://www.foo.com/base"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.foo.com/userextension extension.xsd"
language="en-us" xmlns="http://www.foo.com/userextension">
....
</base:RootMsg>
I get an error right away complaining about "base:RoogMsg" not being
defined, when debuging this I see that the error occurs before the
parser tries to load the "extension.xsd" schema. the schema is loaded
just fine and it will validate against the type that is defined there
but it won't validate against anything in the base.xsd.
Is there something wrong with my instance document? or does this sound
like a parser problem?
thanks in advance for your help.
Eugene
[ March 24, 2004: Message edited by: Eugene Yusim ]
G Buddha
Greenhorn

Joined: Mar 23, 2004
Posts: 4
All I could think is there is some problem with the name space you are using, though not in the instance, it may be in the "userextension extension.xsd". Please check whether you are using proper namespace of the base.xsd in the import element of extension.
Eugene Yusim
Greenhorn

Joined: Feb 13, 2004
Posts: 4
ok, got it figured out.
the schemaLocation of the instance document that uses the extension.xsd must also include the base.xsd, so it would look like this:
xsi:schemaLocation="http://www.foo.com/base base.xsd http://www.foo.com/userextension extension.xsd"
G Buddha
Greenhorn

Joined: Mar 23, 2004
Posts: 4
Hi Eugene,
Though this method works, actually what you are trying to do here is explicitly mentioning both the Schema "base.xsd" and "userextension extension.xsd". This is something wrong. Once you imported the "base.xsd" in "userextension extension.xsd" with proper namespace of "base.xsd" then the instance document should not have any problem. If it is still not recognizing "base.xsd" without explicitly mentioning it, it means either your import statement is wrong or the parser you are using is not recognizing import statement at all. In either case, you will run into problem if any of the element in "userextension extension.xsd" has type declared / refered to another element in "base.xsd".
You can check validity of both the schema's in the following site.(Scroll down the site you may find Schema Check)
Schema Check
If that doesn't help, Post the import statement in extension.xsd as well as the Namespace declaration in base.xsd. Let us examine if there is any problem with your schema.
Regards,
G
 
 
subject: schema validation/parser problem