Abolishing Namespaces

Discussion in 'XML' started by tysontate@gmail.com, Aug 9, 2005.

  1. Guest

    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
    , Aug 9, 2005
    #1
    1. Advertising

  2. Andy Dingley Guest

    On 9 Aug 2005 11:03:46 -0700, wrote:

    >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.
    Andy Dingley, Aug 9, 2005
    #2
    1. Advertising

  3. Peter Flynn Guest

    wrote:
    [...]
    > 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.


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

    ///Peter
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
    Peter Flynn, Aug 10, 2005
    #3
  4. 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

    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Priscilla Walmsley, Aug 11, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    namespaces

    valentin tihomirov, May 24, 2004, in forum: VHDL
    Replies:
    0
    Views:
    593
    valentin tihomirov
    May 24, 2004
  2. Craig Deelsnyder

    Best Practices - solution - namespaces - classes

    Craig Deelsnyder, Aug 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    430
    Vincent V
    Aug 4, 2003
  3. Will

    Conflicting namespaces??

    Will, Aug 13, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,683
    Chris R. Timmons
    Aug 13, 2003
  4. ravi sankar
    Replies:
    2
    Views:
    384
    abdul bari
    Aug 27, 2003
  5. D. Shane Fowlkes
    Replies:
    1
    Views:
    928
    Tu-Thach
    Jan 13, 2004
Loading...

Share This Page