PDA

View Full Version : What's the namespace URI actually for?


brothercake
07-26-2003, 09:10 PM
It says in my XML in a Nutshell, unless I've read it wrong, that a namespace URI doesn't actually have to point to anything. So what's it for?

jkd
07-27-2003, 01:48 AM
To uniquely identify an XML application. :)

brothercake
07-27-2003, 04:12 AM
But what's the data for - why is it a URI if it doesn't have to resolve to a document .. or is that the point, that by using your own domain name you guarantee it will be a unique string?

jkd
07-27-2003, 04:32 AM
Originally posted by brothercake
or is that the point, that by using your own domain name you guarantee it will be a unique string?

Yes. Remember, certain applications can use the same tags, hence the need for namespaces. However, you need unique namespaces to resolve this problem, and using URI's as namespace identifiers solve this problem.

Alex Vincent
07-29-2003, 07:13 PM
Originally posted by jkd
To uniquely identify an XML application. :)

A little more detail:

Namespace URI's are how a document separates one XML language from another. The prefixes you see associated with a namespace URI are a convenience for when you want to associate an element or an attribute with a particular XML namespace.

It is correct that a namespace URI doesn't specifically point to a particular document all the time. XHTML 1.x is an exception, in its use of "http://www.w3.org/1999/xhtml", but even then it's a placeholder. An application parsing an XML element or attribute with that namespace attached or included by default will know the element or attribute is an XHTML element.

Now which XHTML language it is, that's not so clear... there's XHTML 1.0 Frameset, XHTML 1.0 Transitional, XHTML 1.0 Strict, XHTML 1.1, XHTML Print (Working Draft), XHTML 2.0 (Working Draft) or any number of XHTML Family languages you could create with the Modularization of XHTML Recommendation...

However, very often the particular variety of XHTML may not matter to a given application reading it.

brothercake
08-02-2003, 05:39 AM
Thanks both for the clarification :)

Basscyst
02-16-2005, 05:22 PM
Ok, this is coming a bit clearer now. I at least understand the purpose, but I don't understand when it should be changed. Should you have a unique namespace for every document? Different sections of a single document? Does it just depend? Here is an exerpt from w3schools. . .

If you take a close look at the XSL document below, you will see that most of the tags are HTML tags. The tags that are not HTML tags have the prefix xsl, identified by the namespace "http://www.w3.org/TR/xsl":

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="CATALOG/CD">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


If the uri for the namespace above was http://www.ilovemuffins.com/blueberry would it still just function as expected? If so, can you not just treat it like an id and increment as you go on. . .is it just that it is expected to be in that format? :confused:

Basscyst

liorean
02-16-2005, 05:40 PM
Well, the idea of namespaces if to remove one of the reasons DTDs were important before. In SGML, you needed a DTD to know what semantics were attached to the respective elements. XML before namespaces, you could still not use two elements from different languages (each langauge with a set of semantics of it's own) in the same document, because the DTD was the only way to know what semantics should be used.

Now, namespaces solve this problem by introducing a per element way of specifying which set of semantics should be used for which elements in a document.

The reason to change the namespace should be obvious from that: you need a new namespace for each time you change element/attribute semantics. E.g: XHTML2 made semantics changes that were not compatible with XHTML and indeed HTML. Because of this, they decided that XHTML2 would have a different namespace from XHTML1.



Another result of this is that namespaces makes DTDs an aged and not especially powerful way of validation, since the DTD would need to encompass all namespaces that could possibly be used in the document if you wanted unlimited language interoperability.

Basscyst
02-16-2005, 05:54 PM
ok, so, basically any tag started with the xsl in the script above will be treated as xls. Then how does it know to treat the html as html? Maybe a dumb question. It still throws me off though that they use a uri pointing to an applicable directory, yet it seems apparent that the uri could be anything?

now as far as this line goes:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/xsl">


The xmlns, that is what declares what language is being used? So is there a ns for other languages as well, and that is when it would be changed? Bah, I can throw it in there and make all this work together, but I really don't "get" it. Could you show an example where the lack of a declared namespace actually generated a conflict? Perhaps in a single document. To think I pretty much understood the xml and xls tutorials, aside from namespace, you don't want to get me started on xsl-fo. :confused:

Edit:

ok, I re-read tutorial. Both these "trees" could be in the same file right?


<table xmlns="http://www.w3.org/TR/html4/">
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
<table xmlns="http://www.w3schools.com/furniture">
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>


Then you could reference all furniture tables or all data tables based on the namespace, right? If that's right, I think I got it. Though I still feel frustrated, so maybe I didn't. :o

Basscyst