Abolishing Namespaces

T

tysontate

I've been charged with updating old schemas for various files that have
never actually been validated against each other. I've got the schema
itself in good form at this point - I'm positive that they're pretty
clean. My only remaining problem is namespaces.

The XML files, which I can't modify, use no namespaces at all. They
contain elements from as many as four different files. Example:

"CargoList" in CargoList.xsd contains a sequence of "Cargo" elements
which are defined in Cargo.xsd, which uses simple types (things like
certain ID number formats etc.) defined in xyzcorptypes.xsd

As they are now, the schemas use namespaces, but most of them are
broken in weird ways.

What I'd like to do is abolish namespaces in these schemas. This would
make things a lot easier for me, I'm sure. There are no collisions
among all the different schemas, so I'm not worried about that. Is it
possible to make everything "global"?

Here's a sample problem I'm having, but I don't know if it's related to
the namespaces:

I have a schema like so:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.xyzcorp.com/CargoLi st"
xmlns="http://www.xyzcorp.com/CargoLi st"
xmlns:xs="http://www.w3.org/2001/XMLSche ma"
xmlns:crg="http://www.xyzcorp.com/Cargo"xmlns:cdm="http://www.xyzcorp.com/xyzcorptypes">
<xs:import
namespace="http://www.xyzcorp.com/xyzcorptypes"schemaLocation="xyzcorptypes.xsd"/>
<xs:import
namespace="http://www.xyzcorp.com/Cargo"schemaLocation="Cargo.xsd"/>
<xs:element name="CargoList">
.............Complex Type etc. etc...........

And an xml file like so:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<CargoList IDNumber="788723">
<Cargo............. attributes etc.............

I get the following error when I run it through my Java SAX validator:
"Cannot find the declaration of element 'CargoList'." on the second
line of the xml file.

Any help/tips/links are appreciated.

Thanks!
-Tyson
 
A

Andy Dingley

There are no collisions
among all the different schemas, so I'm not worried about that. Is it
possible to make everything "global"?

No collisions ? Then it's easy to merge them into a single namespace.
 
P

Peter Flynn

I have a schema like so:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.xyzcorp.com/CargoLi st"
xmlns="http://www.xyzcorp.com/CargoLi st"
xmlns:xs="http://www.w3.org/2001/XMLSche ma"
xmlns:crg="http://www.xyzcorp.com/Cargo"xmlns:cdm="http://www.xyzcorp.com/xyzcorptypes">
namespace="http://www.xyzcorp.com/xyzcorptypes"schemaLocation="xyzcorptypes.xsd"/>
<xs:import
namespace="http://www.xyzcorp.com/Cargo"schemaLocation="Cargo.xsd"/>
<xs:element name="CargoList">
............Complex Type etc. etc...........

And an xml file like so:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<CargoList IDNumber="788723">
<Cargo............. attributes etc.............

I get the following error when I run it through my Java SAX validator:
"Cannot find the declaration of element 'CargoList'." on the second
line of the xml file.

Maybe it's declared as crg:CargoList not plain CargoList.

///Peter
 
P

Priscilla Walmsley

Hi,

All you have to do is:

1. remove the targetNamespace attribute from all the schemas, and

2. change all the xs:import elements to xs:include elements (and remove
the namespace attribute from those)

3. You can also delete all the namespace declarations in your schema,
except for the one that defines the xs: prefix
(xmlns:xs="http://www.w3.org/2001/XMLSchema").

Hope that helps,
Priscilla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top