XML Namespace question

Discussion in 'XML' started by bfrederi, Jan 7, 2008.

  1. bfrederi

    bfrederi Guest

    How do I create an XML namespace?

    Say I have one defined in my root element: xmlns:namespacename="http://
    theurigoeshere.com/xmlnamespace"
    How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    like this one does: http://purl.org/dc/elements/1.1/
    I know there is a way that the uri will return the actual name of the
    namespace, but how?
     
    bfrederi, Jan 7, 2008
    #1
    1. Advertising

  2. bfrederi wrote:
    > How do I create an XML namespace?
    >
    > Say I have one defined in my root element: xmlns:namespacename="http://
    > theurigoeshere.com/xmlnamespace"
    > How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    > like this one does: http://purl.org/dc/elements/1.1/
    > I know there is a way that the uri will return the actual name of the
    > namespace, but how?


    I am not sure what you are asking about. URI used for namespace do not
    need to point to an actual resource. URIs are simply used to have unique
    names. In the example
    <pf:root xmlns:pf="http://example.com/2008/ns1">
    the namespace name is http://example.com/2008/ns1 and pf is a prefix
    bound to that name.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 7, 2008
    #2
    1. Advertising

  3. In article <>,
    bfrederi <> wrote:

    >How do I create an XML namespace?


    That deends what you mean by "create".

    >Say I have one defined in my root element: xmlns:namespacename="http://
    >theurigoeshere.com/xmlnamespace"
    >How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    >like this one does: http://purl.org/dc/elements/1.1/


    You put something on the webserver for the URI in question.

    But you don't usually have to do this to use a namespace. For
    example, a schema validator may try to open the URI to find a schema,
    but there will be an alternative way to provide the schema directly.

    >I know there is a way that the uri will return the actual name of the
    >namespace, but how?


    I don't understand this question. The URI *is* the name of the
    namespace.

    -- Richard
    --
    :wq
     
    Richard Tobin, Jan 7, 2008
    #3
  4. bfrederi

    Guest

    On 7 Jan, 16:51, bfrederi <> wrote:
    > How do I create an XML namespace?


    An XML namespace identifier is basically a string. However, by
    convention it is done in the form of an HTTP URI (http://...). Even
    if you make it an HTTP URI though, that doesn't mean that the URI has
    to resolve to a real web page!

    > Say I have one defined in my root element: xmlns:namespacename="http://
    > theurigoeshere.com/xmlnamespace"
    > How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    > like this one does: http://purl.org/dc/elements/1.1/
    > I know there is a way that the uri will return the actual name of the
    > namespace, but how?


    Just put up a web page and serve what ever you think's appropriate in
    the normal way - or not as the case may be!

    HTH,

    Pete Cordell
    Codalogic
    Visit http://www.codalogic.com/lmx/ for XML C++ data binding
     
    , Jan 7, 2008
    #4
  5. wrote:
    > An XML namespace identifier is basically a string.


    More specifically, an XML namespace identifier is a string in the form
    of an Absolute URI Reference. Note that they are compared *as* strings;
    if you use two different URIs as namespaces, they are two different
    namespaces, even if both URIs resolve to the same resource. Note too
    that there is no requirement that there actually be a resource
    retrievable via that URI.

    Namespaces are based on URIs because "we already know how to manage URIs
    for uniqueness". But all they are is a way of distinguishing names, so
    you can tell whether an <address> element refers to a postal address, a
    memory address, or a state-of-the-union address.

    So the way you "create a namespace" is to start using it. One of the
    more useful things you can do with it is to use it in an XML Schema
    which defines a kind of document which uses that namespace.



    However, by
    > convention it is done in the form of an HTTP URI (http://...). Even
    > if you make it an HTTP URI though, that doesn't mean that the URI has
    > to resolve to a real web page!
    >
    >
    >>Say I have one defined in my root element: xmlns:namespacename="http://
    >>theurigoeshere.com/xmlnamespace"
    >>How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    >>like this one does: http://purl.org/dc/elements/1.1/
    >>I know there is a way that the uri will return the actual name of the
    >>namespace, but how?

    >
    >
    > Just put up a web page and serve what ever you think's appropriate in
    > the normal way - or not as the case may be!
    >
    > HTH,
    >
    > Pete Cordell
    > Codalogic
    > Visit http://www.codalogic.com/lmx/ for XML C++ data binding



    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 7, 2008
    #5
  6. bfrederi a écrit :
    > How do I create an XML namespace?
    >
    > Say I have one defined in my root element: xmlns:namespacename="http://
    > theurigoeshere.com/xmlnamespace"
    > How do I get that http://theurigoeshere.com/xmlnamespace to resolve
    > like this one does: http://purl.org/dc/elements/1.1/
    > I know there is a way that the uri will return the actual name of the
    > namespace, but how?


    consider this :

    xmlns:foo="urn:isbn:5-454-66546-x"
    xmlns:cat="urn:eek:asis:names:tc:entity:xmlns:xml:catalog"
    xmlns:my="tag:example.com,2008:movies"

    none of these URIs is pointing to something
    namespace URIs are just formal identifiers

    parsers are not expected to find some resources with them, although the
    more often people do use URLs and may put some description of the
    namespace, but it is not for processing purpose

    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
     
    Philippe Poulard, Jan 7, 2008
    #6
  7. bfrederi

    bfrederi Guest

    I guess I should be more specific in what I am doing. I am using
    ElementTree in python, and when I add the dublin core namespace
    "http://purl.org/dc/elements/1.1/" to my elements when creating my
    XML, it automatically knows that the uri "http://purl.org/dc/elements/
    1.1/" is supposed to be known as "dc". So it automatically add this to
    my root element: xmlns:dc="http://purl.org/dc/elements/1.1/" and to
    all the of elements I have attached the uri "http://purl.org/dc/
    elements/1.1/" to, it puts a "dc:element" for the element name. So
    somehow the uri is able to resolve to an alias of "dc". How do I
    create my own uri that will resolve as such? Do I need to create some
    sort of reference file that does something of the effect of namespace
    = "http://www.example.com/namespace/" or is it an apache setting, etc?
     
    bfrederi, Jan 7, 2008
    #7
  8. bfrederi wrote:
    > I guess I should be more specific in what I am doing. I am using
    > ElementTree in python, and when I add the dublin core namespace
    > "http://purl.org/dc/elements/1.1/" to my elements when creating my
    > XML, it automatically knows that the uri "http://purl.org/dc/elements/
    > 1.1/" is supposed to be known as "dc". So it automatically add this to
    > my root element: xmlns:dc="http://purl.org/dc/elements/1.1/" and to
    > all the of elements I have attached the uri "http://purl.org/dc/
    > elements/1.1/" to, it puts a "dc:element" for the element name. So
    > somehow the uri is able to resolve to an alias of "dc". How do I
    > create my own uri that will resolve as such? Do I need to create some
    > sort of reference file that does something of the effect of namespace
    > = "http://www.example.com/namespace/" or is it an apache setting, etc?


    The documentation here
    <URL:http://effbot.org/zone/element.htm#xml-namespaces> says: "the
    writer will automatically generate proper XML namespace declarations,
    and pick a suitable prefix". You will have to ask the creator of that
    library how the prefix is choosen. I am pretty sure it is not done by
    accessing the URL.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 7, 2008
    #8
  9. The prefix chosen doesn't matter. If the tool has promised it will take
    care of this, it's the tool's responsibility (more accurately, the XML
    Serializer's responsibility) to either generate or select an appropriate
    prefix and bind it correctly, or to use default namespaces, or both,
    when it writes out the XML. The DOM Level 3 spec describes one way this
    can be done, but the precise algorithm doesn't matter as long as
    everything winds up bound to the right namespace URI.

    I haven't used that Python tool, so I don't know what approach it's
    using. Check with whoever authored that tool?


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 7, 2008
    #9
  10. bfrederi

    bfrederi Guest

    > The documentation here
    > <URL:http://effbot.org/zone/element.htm#xml-namespaces> says: "the
    > writer will automatically generate proper XML namespace declarations,
    > and pick a suitable prefix". You will have to ask the creator of that
    > library how the prefix is choosen. I am pretty sure it is not done by
    > accessing the URL.


    You know? Now that I think about it. The prefix may already be defined
    somewhere with in the library. You're almost definitely right. It just
    seems highly improbable that they would include that specific
    namespace... weird.

    I did find a way to add my namespace using the
    elementtree.ElementTree._namespace_map property. For people familiar
    with python (hopefully someone will come across this as a future
    reference), it's a dictionary of namespaces:
    import elementtree
    prefix = 'yourprefix'
    namespace = 'http://www.example.com/namespace'

    elementtree.ElementTree._namespace_map.update({namespace:prefix})
    or (whichever syntax your prefer)
    elementtree.ElementTree._namespace_map[namespace] = prefix

    So now, in Python and ElementTree, if you prefix your elements with
    the namespace:
    new_element = Element('{'+namespace+'}'+"elementname")

    your element will now have the namespace prefix attached:
    <yourprefix:elementname/>

    Thanks for your help everyone.
     
    bfrederi, Jan 7, 2008
    #10
  11. bfrederi

    The Magpie Guest

    bfrederi wrote:
    > How do I create an XML namespace?
    >

    Name it in an XML document or Schema. Job done.
     
    The Magpie, Jan 7, 2008
    #11
    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. Èý¹â
    Replies:
    1
    Views:
    574
    William F. Robertson, Jr.
    Jul 29, 2003
  2. Replies:
    0
    Views:
    5,137
  3. Anonymous
    Replies:
    3
    Views:
    534
    Ron Natalie
    Aug 18, 2003
  4. Jason Heyes
    Replies:
    1
    Views:
    452
    Woebegone
    Nov 19, 2004
  5. Petter Reinholdtsen
    Replies:
    9
    Views:
    4,372
    Howard
    Nov 29, 2004
Loading...

Share This Page