Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Namespaces question.....

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious.....
Can an element be from one namespace and have an attribute from a different namespace?
Anyone tried this or come across such a situation?
Thanks.
- madhav
ps: Right now, I don't have time to verify so I thought I will just ask. Forgive me, but I am not being lazy.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take an example to illustrate this (from XML in a Nutshell 2nd).

In the XML excerpt above, the default namespace (mentioned by the xmlns attribute), only applies to the elements (svg, ellipse and rect) and not to the attributes (rx, ry, ...). Those attributes are not in any namespace.
An example of this can be seen when using XLink where the "href" and the "type" attributes have to be prefixed with "xlink" (or any other prefix mapping to the XLink namespace).
[ February 10, 2003: Message edited by: Valentin Crettaz ]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Val:
I agree with what you said abt the elements.
That said, can I do this:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:foo="http://www.foo.org" width="12cm" height="10cm">
<ellipse foo:rx="110" foo:ry="130" />
<rect x="4cm" y="1cm" width="3cm" height="6cm" />
</svg>

Maybe I should ask if attributes even have namespaces ?
Thanks.
- madhav
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind.
Found the answer in the Namespace Spec.
It's possible.
- madhav
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Madhav, I went home
Happy you found the answer.
To summarize:
- elements may belong to a specific namespace or no namespace at all.
- attributes may also belong to a specific namespace or no namespace at all.
- if an element is in a specific namespace, all unprefixed attributes of that element are not implicitely in the element's namespace, in fact, they are in no namespace at all.
- it is possible that an element be in a namespace and one (or more) of its attributes be in other namespaces (think XLink).
- it is not possible to put an attribute in a default namespace without prefixing it as it is the case with elements (xmlns attribute).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic