understanding noNamespaceSchemaLocation

Discussion in 'XML' started by cartoper@gmail.com, Jan 7, 2007.

  1. Guest

    XML, Schemas, and XSLT has been part of my life for a number of years
    now, but I have always used it in desktop application where I simply
    make the noNamespaceSchemaLocation attribute the name of the schema
    because it is going to reside in the same location as the xml file.

    I am now working on a project that is a bit more complex. Again part
    is a desktop application which will not have access to the Internet all
    the time, but another part of the project does have access to the
    Internet. It is my understanding that within the XML, it is possible
    to provide a URL as the namespace name.

    How exactly do I go about setting up the XML so that when it is
    validated on the desktop application, I can simply provide the schema
    like I always have and then on the web it uses the URL as the source.

    I don't think my question makes any sense. What I am really looking
    for is a good tutorial on just namespaces and how they work. Any
    suggestions?
    , Jan 7, 2007
    #1
    1. Advertising

  2. Peter Flynn Guest

    wrote:
    > XML, Schemas, and XSLT has been part of my life for a number of years
    > now, but I have always used it in desktop application where I simply
    > make the noNamespaceSchemaLocation attribute the name of the schema
    > because it is going to reside in the same location as the xml file.
    >
    > I am now working on a project that is a bit more complex. Again part
    > is a desktop application which will not have access to the Internet all
    > the time, but another part of the project does have access to the
    > Internet. It is my understanding that within the XML, it is possible
    > to provide a URL as the namespace name.


    It's the other way around: a namespace name MUST be a URI. The URI
    syntax allows for interpretation as a local filename, either relative to
    the current location or absolute to your local hard disk, or as a
    network resource (starting with http://, ftp://, etc)...however, the use
    of local names is deprecated in namespaces.

    I'm afraid noNamespaceSchemaLocation is just an unpleasant kludge: the
    Namespaces Spec says "It is not a goal that it [the namespace name] be
    directly usable for retrieval of a schema (if any exists)."

    > How exactly do I go about setting up the XML so that when it is
    > validated on the desktop application, I can simply provide the schema
    > like I always have and then on the web it uses the URL as the source.


    You need to ask your software manufacturer for any non-standard feature
    they may have provided. It's also a bit risky. What happens if the local
    copy and the network copy go out of sync?

    It's a great pity Schemas were not implemented using the DOCTYPE
    declaration like DTDs, then we would have had PUBLIC and SYSTEM catalog
    resolution at our disposal. Unfortunately this would have entailed
    another TC to ISO 8879 and another tedious decade teaching developers
    how to do catalog resolution properly.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Jan 7, 2007
    #2
    1. Advertising

  3. Guest

    Peter Flynn wrote:
    > wrote:
    > > XML, Schemas, and XSLT has been part of my life for a number of years
    > > now, but I have always used it in desktop application where I simply
    > > make the noNamespaceSchemaLocation attribute the name of the schema
    > > because it is going to reside in the same location as the xml file.
    > >
    > > I am now working on a project that is a bit more complex. Again part
    > > is a desktop application which will not have access to the Internet all
    > > the time, but another part of the project does have access to the
    > > Internet. It is my understanding that within the XML, it is possible
    > > to provide a URL as the namespace name.

    >
    > It's the other way around: a namespace name MUST be a URI. The URI
    > syntax allows for interpretation as a local filename, either relative to
    > the current location or absolute to your local hard disk, or as a
    > network resource (starting with http://, ftp://, etc)...however, the use
    > of local names is deprecated in namespaces.
    >
    > I'm afraid noNamespaceSchemaLocation is just an unpleasant kludge: the
    > Namespaces Spec says "It is not a goal that it [the namespace name] be
    > directly usable for retrieval of a schema (if any exists)."


    Peter,

    First off, thank you for your help! I am guessing here, but my
    impression is thta things work this way:

    Xml with a namespace of: urn:/cartoper/schema1
    actual schema name: MyFirstSchema.xsd

    When loading MyFirstSchema.xsd into the validator, there will be a way
    to tell the validator that it's namespace is urn:/cartoper/schema1.

    Or is it that I have to place the urn:/cartoper/schema1 in the schema,
    too?
    , Jan 7, 2007
    #3
  4. wrote:

    > Xml with a namespace of: urn:/cartoper/schema1
    > actual schema name: MyFirstSchema.xsd
    >
    > When loading MyFirstSchema.xsd into the validator, there will be a way
    > to tell the validator that it's namespace is urn:/cartoper/schema1.
    >
    > Or is it that I have to place the urn:/cartoper/schema1 in the schema,
    > too?


    If you want to author a schema defining elements in that namespace then
    use targetNamespace="urn:/cartoper/schema1" e.g.

    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:/cartoper/schema1"
    elementFormDefault="qualified">


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 7, 2007
    #4
  5. Guest

    Martin Honnen wrote:
    > wrote:
    >
    > > Xml with a namespace of: urn:/cartoper/schema1
    > > actual schema name: MyFirstSchema.xsd


    > If you want to author a schema defining elements in that namespace then
    > use targetNamespace="urn:/cartoper/schema1" e.g.
    >
    > <xs:schema
    > xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > targetNamespace="urn:/cartoper/schema1"
    > elementFormDefault="qualified">


    Martin,

    Ok, that makes perfect sense, after doing some digging;) The final
    questions is: What exactly do I put in the XML? I am using XMLSpy as
    my editor. When I assign the schema to the xml file, it generates this
    attributes to the root element:

    xmlns="urn:/cartoper/schema1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:/cartoper/schema1 D:\<full
    path>\MyFirstSchema.xsd"

    When I removed the full path from the xsi:schemaLocation attribute
    (xsi:schemaLocation="urn:/cartoper/schema1 MyFirstSchema.xsd"), XmlSpy
    complains that it is not valid. Do I simply need to leave off the
    xsi:schemaLocation? Or is there some way I can still have the xml
    point to the schema being in the same directory? I sort of like how
    XMLSpy will validate the XML for me, I use it mostly in development.
    , Jan 7, 2007
    #5
  6. Guest

    Anyone?

    wrote:
    > Martin Honnen wrote:
    > > wrote:
    > >
    > > > Xml with a namespace of: urn:/cartoper/schema1
    > > > actual schema name: MyFirstSchema.xsd

    >
    > > If you want to author a schema defining elements in that namespace then
    > > use targetNamespace="urn:/cartoper/schema1" e.g.
    > >
    > > <xs:schema
    > > xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > > targetNamespace="urn:/cartoper/schema1"
    > > elementFormDefault="qualified">

    >
    > Martin,
    >
    > Ok, that makes perfect sense, after doing some digging;) The final
    > questions is: What exactly do I put in the XML? I am using XMLSpy as
    > my editor. When I assign the schema to the xml file, it generates this
    > attributes to the root element:
    >
    > xmlns="urn:/cartoper/schema1"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocation="urn:/cartoper/schema1 D:\<full
    > path>\MyFirstSchema.xsd"
    >
    > When I removed the full path from the xsi:schemaLocation attribute
    > (xsi:schemaLocation="urn:/cartoper/schema1 MyFirstSchema.xsd"), XmlSpy
    > complains that it is not valid. Do I simply need to leave off the
    > xsi:schemaLocation? Or is there some way I can still have the xml
    > point to the schema being in the same directory? I sort of like how
    > XMLSpy will validate the XML for me, I use it mostly in development.
    , Jan 8, 2007
    #6
  7. wrote:
    > Anyone?


    >> Ok, that makes perfect sense, after doing some digging;) The final
    >> questions is: What exactly do I put in the XML? I am using XMLSpy as
    >> my editor.


    You might want to ask XMLSpy specific questions in an XMLSpy user forum
    as there you have a better chance to find other users of that software
    than in a generic comp.text.xml group.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 8, 2007
    #7
  8. Guest

    Martin Honnen wrote:
    > wrote:
    > > Anyone?

    >
    > >> Ok, that makes perfect sense, after doing some digging;) The final
    > >> questions is: What exactly do I put in the XML? I am using XMLSpy as
    > >> my editor.

    >
    > You might want to ask XMLSpy specific questions in an XMLSpy user forum
    > as there you have a better chance to find other users of that software
    > than in a generic comp.text.xml group.


    Martin,

    I would agree with you, except, I am trying to understand how exactly
    namespaces, schemas, and xml are all tied together, I am assuming the
    XMLSpy will comply with the way things are, which is not always the
    case;)

    Peter's inital reply implies that it is a bad thing to use the
    xsi:schemaLocation attribute. Am I correct? Is there any way of
    denoting in the xsi:schemaLocation that the schema file is in the same
    folder/directory as the XML?
    , Jan 8, 2007
    #8
    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. George Hester
    Replies:
    3
    Views:
    3,479
    Carl Prothman [MVP]
    Aug 11, 2003
  2. Tjerk Wolterink
    Replies:
    1
    Views:
    1,571
    Tjerk Wolterink
    Sep 1, 2005
  3. Elhanan
    Replies:
    0
    Views:
    568
    Elhanan
    May 22, 2006
  4. Jean-François Michaud

    disregarding xsi:noNamespaceSchemaLocation?

    Jean-François Michaud, Apr 14, 2008, in forum: XML
    Replies:
    2
    Views:
    681
    Jean-François Michaud
    Apr 14, 2008
  5. tooshiny
    Replies:
    1
    Views:
    377
    Stefan Behnel
    Jun 4, 2009
Loading...

Share This Page