T
Tom Anderson
Hi,
I don't know if this is the appropriate newsgroup for questions about DOM,
so feel free to tell me to get lost.
Anyway, i'm puzzling over why createElementNS takes a qualified name,
rather than a local one. I thought the sole function of a qualified name
in XML is to enable the parser to figure out which namespace an element
belongs to, a sort of macro function that means we don't have to write
things like
<http://www.w3.org/1999/xhtml:p>This is a paragraph that looks like it is
sticking its tongue out.</http://www.w3.org/1999/xhtml:p>
Not that that would be legal, but i hope you see what i mean.
I mean, i can write this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="http://www.w3.org/1999/xhtml">
<foo:body>
</foo:body>
</html>
And it works, right? What matters is the namespace, not the prefix that
happens to be in use.
So why do i need to specify a prefix, by giving a qualified name, in
createElementNS? And does it need to be the same as the prefix in use in
the rest of the document? For instance, if i have a document:
<foo:root xmlns:foo="http://example.invalid/fooNS">
<foo:content/>
</foo:root>
And i do a createElementNS("http://example.invalid/fooNS", "bar:content"),
and appendChild it to the root element, will that 'work'? Do the rules say
that the appended element should behave just like the parsed one? I
realise that DOM calls which inspect the prefix or nodeName attributes of
the element will see the 'bar' prefix, but can i rely on most code (define
that how you will) doing the right thing (ditto)?
The production for qualified names in the namespace spec says that the
prefix is optional; does that mean i can omit it, saying
createElementNS("http://example.invalid/fooNS", "content"), and it will
work?
Should i, for theoretical, practical, or aesthetic reasons, attempt to use
the same prefix as used in the rest of the document? Is there a convenient
way to do that? I can't immediately see any such thing in the DOM spec.
As a wider question, why does the DOM even make namespace prefixes
available? As a kind of backwards compatibility?
Thanks in advance for any input,
tom
I don't know if this is the appropriate newsgroup for questions about DOM,
so feel free to tell me to get lost.
Anyway, i'm puzzling over why createElementNS takes a qualified name,
rather than a local one. I thought the sole function of a qualified name
in XML is to enable the parser to figure out which namespace an element
belongs to, a sort of macro function that means we don't have to write
things like
<http://www.w3.org/1999/xhtml:p>This is a paragraph that looks like it is
sticking its tongue out.</http://www.w3.org/1999/xhtml:p>
Not that that would be legal, but i hope you see what i mean.
I mean, i can write this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="http://www.w3.org/1999/xhtml">
<foo:body>
</foo:body>
</html>
And it works, right? What matters is the namespace, not the prefix that
happens to be in use.
So why do i need to specify a prefix, by giving a qualified name, in
createElementNS? And does it need to be the same as the prefix in use in
the rest of the document? For instance, if i have a document:
<foo:root xmlns:foo="http://example.invalid/fooNS">
<foo:content/>
</foo:root>
And i do a createElementNS("http://example.invalid/fooNS", "bar:content"),
and appendChild it to the root element, will that 'work'? Do the rules say
that the appended element should behave just like the parsed one? I
realise that DOM calls which inspect the prefix or nodeName attributes of
the element will see the 'bar' prefix, but can i rely on most code (define
that how you will) doing the right thing (ditto)?
The production for qualified names in the namespace spec says that the
prefix is optional; does that mean i can omit it, saying
createElementNS("http://example.invalid/fooNS", "content"), and it will
work?
Should i, for theoretical, practical, or aesthetic reasons, attempt to use
the same prefix as used in the rest of the document? Is there a convenient
way to do that? I can't immediately see any such thing in the DOM spec.
As a wider question, why does the DOM even make namespace prefixes
available? As a kind of backwards compatibility?
Thanks in advance for any input,
tom