“Matt Gushee” mgushee@havenrock.com wrote in message
And an unqualified name may either have no namespace or be part of a
default namespace (i.e. one defined with no prefix). So if I have a
document like this:
Blablabla
Yadda yadda yadda
the first has no namespace, but the second belongs to the
“http://www.sillyxml.com/” namespace. So,
ns_of_fullname(“N”) yields prefix for outermost scope
Nope, not if you apply it to the second .
I was referring to returning the namespace given a namespace prefix, not the
namespace of an element - but we can extend the discussion to that as well.
Furthermore, the functions operate at a document level, so you are at no
particular place (element) in the DOM when applying the functions - hence
the N.N or X.Y.Z notion.
However, I’d like to add a function similar to ns_name:
ns_of_local_name(element, prefix), which returns the “namespace string” of
the innermost applicable prefix seen from the element. This is the actual
namespace active for that prefix.
When can furthermore include the empty prefix to mean the default and thus
keep things general.
I guess I was thinking mainly of ‘fullname’ and ‘namespace string’,
which are perfectly understandable but not commonly used in XML circles.
Fine - as long as the message gets through - sometimes it helps to be
unconvential when inventing or (or sometimes rediscovering) new things.
BTW: I’ve alwas found it difficult to accept that XML namespaces are
flat -
one namespace cannot belong to another, although the URL’s provide som
sort
of hierarchy. Prefixes are scoped, but that is different.
I’m not sure how much of a problem that really is.
Me neither, I’ve just always assumed they were hierachical so when reading
through the standard (quite a while back), I kept searching for how this was
handled since it wasnt’ stated explicitly that the namespaces were flat. In
programming languages scopes are usually nested, and many things in XML are
also nested.
You can think of the
elements themselves as constituting a kind of namespace hierarchy–and
tools like XPath allow you to easily distinguish between the
elements in the two following examples:
Abraham Lincoln
Gettysburg Address
...
and
A Graham Pinken
3939 A St.
...
So you can process the differently based on whether it’s a
‘/leaders/*/address’ or a ‘customer/address’ …
This is true, but it is also mixing too different concepts so you have to
model the two possibly independent kind of data carefully to avoid
conflicts.
I have my organizations global namespace in a url. I can use this url to
create subnamespaces, and indeed this may be sufficient. However, it would
be nice to say this piece of XML follows a standard convention e.g. docbook,
and use docbook namespace. However, I’d still like to keep everything
completely contained within my organization and possible within a version
namespace. It would be more flexible with nested namespaces, but certainly
you can get away without. This could be a solution in search of a problem.
But when using third party software working on long term live XML database
data, it could become quite relevant.
or to take a more
likely example, distinguish a ‘book/title’ from a ‘section/title’ or a
‘section/section/section/title’. And, unlike DTDs, XML Schema and RELAX
NG allow you to create context-dependent element definitions.
These are aspects I’ll have to look further into, however, XML Schema could
never go beyond whats possible in XML, but might easy some
inter-dependencies during document creation.
There are certainly difficult issues with XML Namespaces–especially
related to what, if any, semantics the namespace URI should have, and
whether unqualified attributes should have no namespace while
unqualified attributes may belong to a default namespace. But if you
know how to work with the element hierarchy, I don’t see what great
advantage there would be in having hierarchical namespaces. I imagine
you’re talking about something like:
See argumentation above.
so that the b:bar element could be referred to as ‘a:b:bar’, and its
namespace URI would resolve to “http://www.example.com/a/b”?
Not exactly, I want to decouple the namespace string or URI from the
hierachy. This is actually an important point. However, I never gave it that
much theoretical brainpower, at least not in relation to XML.
Like in Ruby, if you have nested classes, or better modules, each module
name would have its own URI. Now you can a W3 standard URI inside you own
project and have it be different from the same elements in a different
project (although, as you argue, the elements themselves present a scoping).
Is there
something you could do under this scheme that is difficult or impossible
with flat namespaces? Or is it more a matter of convenience?
Just curious, really.
In the end everything is about convenience but this translates into reduced
risc and increased productivity. Anyway I have had no problems with it - it
just puzzled me.
I’ve been experimenting with implementing globally unqiue identifers via
nested namespaces in an application outside of the XML framework but that is
a different story.
You can also look at the ASN.1 object identifier tree which I believe is
based on a hierarchical model.
I have been very steeped in the SGML/XML
worldview, and I sense that you are more of a programmer, which is of
course fine, but it entails a slightly different way of thinking.
Certainly - to me XML is just one way (a good way) to view a more general
problem and in several ways I feel XML has invaded my space of structured
data models. For example, back in 1995 I used the RIFF file format for a
communcation infrastructure and for interpreted language logic before XML
became all the hype (although SGML was around somewhere). The RIFF format
(known from .WAV files) has the essential features of XML - its a binary
hierachical tagged format using 4 byte tags and a 4 byte length field
instead of an endmarker. (And then the RIFF I/O API is better than the
normal C / Unix file API (fopen and friends) as it has optimized buffering
due to multimedia applications).
Mikkel