On 02/10/12 13:40, Ludovic Kuty wrote:
> Dear group,
>
> In the article entitled "Namespace Myths Exploded"
> (http://www.xml.com/lpt/a/395), there is something (in fact a few
> things but let's focus on this one thing) that bothers me. In Myth 2
> called "Universal names uniquely identify element types and
> attributes" we have a code sample
>
> <?xml version="1.0" ?>
> <A xmlns="http://www.foo.org/">
> <A>abcd</A>
> </A>
>
> And the associated question in the text : "Do these share a single
> element type or do they have two different element types?". I don't
> understand.
The simple answer, strictly by the book (well, the XML Specification) is
that this document has a single element type called A, with two
instances of it. The fact that the first instance has an attribute
called xmlns is misleading and irrelevant.
But as Martin has pointed out, in Schema-land, a namespace binding must
be specified with a prefix, eg
<?xml version="1.0" ?>
<A xmlns:foo="http://www.foo.org/">
<A>abcd</A>
</A>
This binds the first A element *and its content* to the namespace
specified, using the prefix "foo". So the second instance of A also
acquires that namespace, and therefore again, there is a single element
type in use here.
> I thought that the DTD will constrain the element A by
> telling us what is acceptable as attributes and what is acceptable as
> content.
That is correct, but has nothing to do with the question. What you are
describing here is a content model: the specification of what an element
type is permitted to contain.
> Once it is done, how could we get two element types ? I mean A
> should/could be defined as :
>
> <!ELEMENT A (#PCDATA | A)>
> <!ATTLIST A xmlns CDATA #IMPLIED>
Not quite: it should be <!ELEMENT A (#PCDATA | A)*> so that the inner A
is optional, otherwise it would be compulsory and lead to infinite
recursion.
> For me, it is just one type, not two.
Correct.
> How could we get two different element types with the same name?
By using namespaces to distinguish them:
<?xml version="1.0" ?>
<a xmlns:html="http://www.w3.org/1999/xhtml">
<a xmlns:foo="http://www.foo.org/">abcd</a>
</a>
This is an a element type from XHTML containing a completely different a
element type taken from some schema defined by Foo, Inc. Two separate
types of element.
In XML processing (eg XPath), the name() function will reference the
prefixed name (eg html:a or foo:a) and the local-name() function will
reference the unprefixed name (a in both cases).
> I understand that it "could" be possible to distinguish them based on
> the context but I don't think DTDs or W3C XML Schemas allow this.
You can infer a namespace by the context in the sense that all the
content of an element in one namespace is held to be in the same
namespace unless specified otherwise as above. But no, in the general
sense, unmarked, you cannot infer a *distinction* between elements based
on namespace, where the namespace is not given.
> Also, I would be interested in any resource (book, article, Web
> page, ...) that talks about "element types" and not just "elements"
> and that is quite formal about XML. You may point me to the right
> location in the XML recommendation.
The formal distinction comes from SGML, so the canonical location is ISO
8879:1988. You can still buy Charles Goldfarb's _SGML Handbook_, where
you will find it explained in production 117 at p.406 (the term actually
goes back much further into markup history). You will find the terms
used in this way in any book or web page written for the formal
discussion of markup.
What you declare in a DTD or Schema are element types. An element of
type A in [old] HTML is for marking a hypertext Anchor. There can only
ever be one of each (modulo the use of namespaces to distinguish
conflicting names), because you can only declare an element type once.
What you use in documents are element instances: in effect, this term
describes occurrences of elements of a particular type, and is usually
what is meant by the word "element".
The looser use of the word "element" to cover both meanings is
widespread in informal discussion.
For more discussion, see
http://www.flightlab.com/~joe/sgml/faq-not.txt
especially Part 5
///Peter
--
XML FAQ:
http://xml.silmaril.ie