XML Namespace question

M

Martin Honnen

bfrederi said:
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.
 
R

Richard Tobin

bfrederi said:
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
 
U

usenet

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
 
J

Joseph Kesselman

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
 
P

Philippe Poulard

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 !
 
B

bfrederi

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?
 
M

Martin Honnen

bfrederi said:
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.
 
J

Joseph Kesselman

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?
 
B

bfrederi

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.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top