PDA

View Full Version : Namespaces


safalkishore
12-05-2003, 12:26 PM
Confusion with namespases

If u notice in most places we normally use the syntax
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/xsl">

whats the reason why we use such a namespace "http://www.w3.org/TR/xsl". If u dont use the above syntax it doesnt work
Do u know the reason for that?
Obviously the parser does not connect to that website
Whats the significance of that URL???

liorean
12-05-2003, 01:34 PM
The namespace is the thing which connects a tag with a proprietary handling pattern in XML. For example, an XHTML document uses the XHTML namespace because it is that namespace, and nothing else, that is associated with the default handling of XHTML. The same goes for XSL. If you don't specify a namespace, but provide a DOCTYPE, you have only stated which grammar the document should be/is conformant to, but you have not stated anything that provides the association towards non-XML specified handling. A language may very well use several namespaces, and a namespace may be used by several languages, so the namespace and the languages are really not related. The DTD does not in itself describe a language, it describes a document grammar. A document may contain many languages, but all the elements used in it must be specified in the DTD for the document to be valid. Thus, the grammar is separated from the language which is separated from the handling. With XSL, the handling is tres importante, because there is little other use for the language.

The namespace uri is really just an identifier. In the future, there might come a way of associating the namespave uri with a handling, but currently it's just a name for the user agent to recognise.

me'
12-06-2003, 12:54 PM
So, following on from that, how important is it that we include a xmlns="" attribute in the <html> tag for xhtml?

liorean
12-06-2003, 03:45 PM
In a correct XML/XHTML engine, if you haven't specified the namespace on the html element, the html should not have any default behavior or styling. This means:

- a and link elements have no built-in linking capability except for what XLink or HLink provides
- img, object, iframe, frameset/frame and input type="image" have no built-in embedding functionality
- meta, script and style elements loses any special behavior or parsing
- Form fields and form elements have no special rendering, behavior or meaning
- Every element loses it's default rendering and instead renders as inline elements, with the exception of the pre, style and script elements, who have their whitespace preservation written into the DTD. A user agent isn't required to read the DTD and may without breaking the specification collapse whitespace in them, though.


<!ELEMENT html (head, body)>
<!ATTLIST html
%i18n;
id ID #IMPLIED
xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
>Note that the xmlns of the html element is fixed. That doesn't necessarily mean anything in a non-validating user agent, but it means that a validating user agent would by default know it. However, this is what W3C says about that:
From Namespaces in XML <http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared>:
Namespace Constraint: Prefix Declared
The namespace prefix, unless it is xml or xmlns, must have been declared in a namespace declaration attribute in either the start-tag of the element where the prefix is used or in an an ancestor element (i.e. an element in whose content the prefixed markup occurs). The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. The prefix xmlns is used only for namespace bindings and is not itself bound to any namespace name.

This constraint may lead to operational difficulties in the case where the namespace declaration attribute is provided, not directly in the XML document entity, but via a default attribute declared in an external entity. Such declarations may not be read by software which is based on a non-validating XML processor. Many XML applications, presumably including namespace-sensitive ones, fail to require validating processors. For correct operation with such applications, namespace declarations must be provided either directly or via default attributes declared in the internal subset of the DTD.



...All of which of course means, that the namespace declaration is perhaps even more important than the DOCTYPE, and should under no circumstances be left out.