2

When extending XHTML for a very simple CMS, I'm wondering if I should use

<cms:include document="foo/bar" />

or

<cms:include cms:document="foo/bar" />

Given a document declared as follows:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:cms="http://spongegroup.com/ns/cms">

(basically the idea is to make a simple parser that white-lists a few XHTML tags, and adds a couple of my own).

Is the cms: prefix needed on attributes of an element that is already in the cms: namespace?

1 Answer 1

3

You do not need the cms: prefix on the attributes of cms: elements, because the meaning of these attributes is determined by the element they belong to.

See the XML namespace recommendation: “the interpretation of unprefixed attributes is determined by the element on which they appear”.

Technically speaking however, unprefixed attributes belong to the null namespace.

Answer edited on 2011-06-06 to correct a misleading sentence. Thanks to the commenters.

Sign up to request clarification or add additional context in comments.

5 Comments

"By default, the XML attributes of a given element belong to this element's namespace". That's either wrong or misleading. Unprefixed attributes are always in the null namespace, not the XML namespace of the element to which they belong. What the quote you give means is that the attribute is sufficiently qualified by the element to which it belongs, not that it adopts the element's namespace. You are correct that the attribute does not need to have a prefix or namespace assigned to it.
Thanks guys... seems like a subtle distinction to me, but it's good that I don't need the ns: prefix on every attribute.
Downvote as the answer is simply wrong - please rephrase. Alochi is correct; attributes are in the null namespace by default. Not being aware of this will cause serious problems when trying to use things like XSLT.
I partially rephrased the answer to correct the misleading sentence.
Ok. I still wouldn't use the phrase "sufficiently qualified" as it will be confused with "qualified name" when what you really mean is "disambiguated" or something similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.