Re: The "real" reason why xmlns should "not" be used

Hello Toby

Toby Inkster wrote:
> On Wed, 2009-08-12 at 14:10 +0100, Martin McEvoy wrote:
>   
>> If I remove all the namespace declarations from the example I gave you 
>> there is no problems parsing the document as XML
>>
>> http://www.validome.org/xml/validate/?lang=en&viewSourceCode=1&url=http://weborganics.co.uk/test/xhtml-test2.xhtml
>>     
>
> Yes that document is valid whereas your first one was not, but my point
> is that the namespace declarations are not the real reason your first
> document was invalid. The following document, which contains no Dublin
> Core namespace declaration is equally invalid:
>
> <?xml version="1.0" encoding="UTF-8"?> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
> "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> 
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
> <head> 
>  <title>xhtml test</title> 
> </head> 
> <body> 
> <h1>XHTML test</h1> 
> <div foo-dc="http://purl.org/dc/elements/1.1/"> 
>   <h2 property="dc:title">The trouble with Bob</h2> 
>   <h3 property="dc:creator">Alice</h3> 
> </div> 
> <bar-div foo-dc="http://purl.org/dc/elements/1.1/"> 
>   <h2 property="dc:title">The trouble with Bob</h2> 
>   <h3 property="dc:creator">Alice</h3> 
> </bar-div>  
> </body> 
> </html>

Agreed but so is this

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
 <title>xhtml test</title> 
</head> 
<body> 
<h1>XHTML test</h1> 
<div xmlns:dc="http://purl.org/dc/elements/1.1/"> 
  <h2 property="dc:title">The trouble with Bob</h2> 
  <h3 property="dc:creator">Alice</h3> 
</div> 
</body> 
</html>

this bit is the problem


<div xmlns:dc="http://purl.org/dc/elements/1.1/"> 
... 

</div> 


the error is Attribute "xmlns:dc" must be declared for element type 
"div". ie:

<dc:div xmlns:dc="http://purl.org/dc/elements/1.1/"> 
... 

</dc:div>


of course you cant do that because XHTML does not support the element <dc:div />

So there is a problem I think with using xmlns:foo and should be avoided if you intend to serialize your document as XML.


Best wishes

-- 
Martin McEvoy
http://weborganics.co.uk/

Received on Wednesday, 12 August 2009 15:06:34 UTC