Newbie: schema on local file system

Discussion in 'XML' started by maxwell@ldc.upenn.edu, Feb 20, 2007.

  1. Guest

    I'm trying to develop a schema, and test it on some sample data.
    There are plenty of examples out there on how to develop schemas etc.,
    but they all seem to assume that you give a URI for the schema that
    points to a web address. For now, I do not have the schema in a web-
    accessible place, it's just on the local file system. I'm stuck
    trying to specify the xmlns inside the file.

    If I have the schema in the same directory as the xml data file, I can
    get away with the following first lines in the xml data file (that is,
    it passes muster with xmllint)

    <?xml version="1.0"?>
    <Mo:MorphologicalData xmlns:Mo="Morph.xsd">...

    But if I try for more generality--like putting all my schemas in a
    single directory somewhere else--I can't seem to pull it off. That
    is, if I replace the above couple lines in my xml data file with the
    following:
    <?xml version="1.0"?>
    <Mo:MorphologicalData
    xmlns:Mo="file:///home/mmaxwell/Data/LinguisticSchemas/
    Morph.xsd">
    --then xmllint gives me an error msg:
    > /usr/bin/xmllint --noout --noent --schema Morph.xsd

    MorphTestData.xml
    MorphTestData.xml:4: element MorphologicalData: Schemas validity
    error :
    Element 'Mo:MorphologicalData': No matching global declaration
    available.

    (This is on a Linux file system, and I know the .xsd file exists in
    the specified directory.)

    I tried searching for "file:///" on line to get some examples of how
    to do this, but all of the search engines I tried strip off the
    ":///", even though I quote it, so I get a bunch of irrelevant hits
    with the word "file" in them. Just pointing me to some examples would
    probably suffice.

    Mike Maxwell
    , Feb 20, 2007
    #1
    1. Advertising

  2. wrote:
    > I'm trying to develop a schema, and test it on some sample data.
    > There are plenty of examples out there on how to develop schemas etc.,
    > but they all seem to assume that you give a URI for the schema that
    > points to a web address. For now, I do not have the schema in a web-
    > accessible place, it's just on the local file system. I'm stuck
    > trying to specify the xmlns inside the file.


    I think you do not understand that a namespace is simply denoted by a
    URL. There does not have to be any resource at that URL and usually or
    at least often is not. So http://www.w3.org/1999/xhtml is the namespace
    URL for XHTML 1. And http://www.w3.org/2000/svg the one for SVG 1.x.
    Nevertheless while you can browser to those URLs you will not find a
    schema there, just a HTML document giving some info on the namespace.

    Schema location URL and namespace URL can be different.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 20, 2007
    #2
    1. Advertising

  3. Guest

    On 20 Feb, 17:06, "" <>
    wrote:
    > If I have the schema in the same directory as the xml data file, I can
    > get away with the following first lines in the xml data file (that is,
    > it passes muster with xmllint)
    >
    > <?xml version="1.0"?>
    > <Mo:MorphologicalData xmlns:Mo="Morph.xsd">...
    >
    > But if I try for more generality--like putting all my schemas in a
    > single directory somewhere else--I can't seem to pull it off. That
    > is, if I replace the above couple lines in my xml data file with the
    > following:
    > <?xml version="1.0"?>
    > <Mo:MorphologicalData
    > xmlns:Mo="file:///home/mmaxwell/Data/LinguisticSchemas/
    > ...


    Although technically the namespace 'URI' is a URI, in practice it is
    just treated as an opague string. Two namespace URIs are considered
    the same if, after white space handling and entity expansion, they are
    identical character-by-character. There is no attempt made to
    dereference the URI.

    For example, http://example.com, http://example.com/, http://www.example.com
    and http://example.com/index.html may all result in the same resource
    being shown. And if there happened to be a schema there, they would
    all result in the same schema being returned. However, from a
    namespace point of view they all represent different namespaces.

    So you probably want to do something like:

    <?xml version="1.0"?>
    <Mo:MorphologicalData xmlns:Mo="http://mycompany.com/
    Morph.xsd">...

    If you want to specify in an XML instance how a schema is found, then
    you can use the xsi:schemaLocation and xsi:noSchemaLocation
    attributes, along the lines of:

    <?xml version="1.0"?>
    <Mo:MorphologicalData xmlns:Mo="http://mycompany.com/Morph.xsd"
    xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xsi:schemaLocation=''file:///home/mmaxwell/Data/
    LinguisticSchemas/Morph.xsd">...

    This is optional though, and the schemaLocation is only considered to
    be a 'hint'.

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 20, 2007
    #3
  4. Guest

    On Feb 20, 2:10 pm, wrote:
    > If you want to specify in an XML instance how a schema is found, then
    > you can use the xsi:schemaLocation and xsi:noSchemaLocation
    > attributes, along the lines of:
    >
    > <?xml version="1.0"?>
    > <Mo:MorphologicalData xmlns:Mo="http://mycompany.com/Morph.xsd"
    > xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    > xsi:schemaLocation=''file:///home/mmaxwell/Data/
    > LinguisticSchemas/Morph.xsd">...


    This gives me a different error msg from xmllint:
    MorphTestData.xml:7: element MorphologicalData:
    Schemas validity error : Element 'Mo:MorphologicalData':
    The attribute 'xsi:schemaLocation' is not allowed.
    MorphTestData.xml fails to validate.
    (Incidently, I'm assuming the line break between "Data/" and
    "LinguisticSchemas/" is an artifact of email, although somewhere I
    vaguely recall that the path and the filename were supposed to be
    separated--not sure why??)

    > This is optional though, and the schemaLocation is only considered
    > to be a 'hint'.


    A hint to whom or what? I was assuming that this was an _instruction_
    to a validation program, but maybe I'm misunderstanding the purpose...

    Mike Maxwell
    , Feb 21, 2007
    #4
  5. Guest

    On 21 Feb, 01:55, "" <>
    wrote:
    > On Feb 20, 2:10 pm, wrote:
    >
    > > <?xml version="1.0"?>
    > > <Mo:MorphologicalData xmlns:Mo="http://mycompany.com/Morph.xsd"
    > > xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    > > xsi:schemaLocation=''file:///home/mmaxwell/Data/
    > > LinguisticSchemas/Morph.xsd">...

    >
    > This gives me a different error msg from xmllint:
    > MorphTestData.xml:7: element MorphologicalData:
    > Schemas validity error : Element 'Mo:MorphologicalData':
    > The attribute 'xsi:schemaLocation' is not allowed.
    > MorphTestData.xml fails to validate.


    Ooops - cut and paste error on my part. I must have opened the wrong
    version of the XSD spec. The xmlns:xsi attribute should be:

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    Sorry about that.

    > (Incidently, I'm assuming the line break between "Data/" and
    > "LinguisticSchemas/" is an artifact of email, although somewhere I
    > vaguely recall that the path and the filename were supposed to be
    > separated--not sure why??)


    yep - e-mail artifact!

    > > This is optional though, and the schemaLocation is only considered
    > > to be a 'hint'.

    >
    > A hint to whom or what? I was assuming that this was an _instruction_
    > to a validation program, but maybe I'm misunderstanding the purpose...


    It's a hint to the validation processor. It's along the lines of
    "Look here for the schema, but if you don't find it there, don't
    complain."

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 21, 2007
    #5
  6. Guest

    > Schema location URL and namespace URL can be different.

    You're right, I totally didn't understand--thanks for the help!

    Mike Maxwell
    , Feb 21, 2007
    #6
    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. Markus
    Replies:
    1
    Views:
    1,490
    Markus
    Nov 23, 2005
  2. Lyndon
    Replies:
    1
    Views:
    505
    Leonard Blaisdell
    Jul 25, 2005
  3. Till Soerensen
    Replies:
    1
    Views:
    1,206
    Henry S. Thompson
    Jun 9, 2004
  4. Replies:
    2
    Views:
    3,254
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,163
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page