Title: Message
Hello again,
 
I've given the issue more thought, and instead of deprecating declaredNamespaces why don't we alter its behaviour (and javadoc) to simply return all its namespaces that are not in the list of namespaces for its parent element? For an element with no parent this would be all of them. This would be a nice convenience method which could be used by anyone wanting to generate output without worrying about namespaces. Generating namespace declarations for each namespace in the list of declaredNamespaces for every element would yield correct documents.
 
The only concern I can see is the expense in time and/or space required to determine what namespaces are in the parent's content but not in the element's.
 
Any thoughts?
 
-- Steen
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Steen Lehmann
Sent: 23. november 2001 20:54
To: 'James Strachan'; [EMAIL PROTECTED]
Cc: Karin Stella Mogensen
Subject: RE: [dom4j-dev] declaredNamespaces containing the element's namespace

Hi James,
 
Ok, so namespaces are resolved at the time the document is created, and not dynamically by walking up the tree until a namespace declaration is found. I was thinking in terms of the actual representation of the document, since I'm working on an editor which needs to constantly maintain this.
 
I agree that declaredNamespaces is superfluous since it's actually just a shorthand for getNamespace() ++ additionalNamespaces(). 
 
On a slightly different, but related note - I was just reading about the Canonical XML representation, which when detaching an element for possible inclusion into another document walks up the tree and looks for attributes in the xml namespace such as xml:lang and xml:space. These are then inserted on the detatched element since they apply to all attributes and elements in the content, unless overridden. It sounds to me like this would be a fairly useful functionality for detach() or an entirely new method - at least I think it would make dom4j more complete. Probably something to put in the "nice to have" section anyway.
 
Thanks,
 
-- Steen
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of James Strachan
Sent: 23. november 2001 15:22
To: Steen Lehmann - SilverStream; [EMAIL PROTECTED]
Subject: Re: [dom4j-dev] declaredNamespaces containing the element's namespace

Hi Steen
 
Let me first give an example before describing the current Namespace behaviour... Imagine this document...
 
<root xmlns:foo="someURI">
    <foo:bar>
        something
    </foo:bar>
</root>
 
Then the <foo:bar> element was detach()'ed from the document and added as the root element to a new document  with code something like this...
 
// parse first doc
SAXReader reader = new SAXReader();
Document original = reader.read( "first.xml" );
Node foobar = original.selectSingleNode( "/root/foo:bar" );
 
// make second doc and output it
DocumentFactory factory = new DocumentFactory();
Document newDoc = factory.createDocument();
newDoc.setRootElement( foobar.detach() );
newDoc.write( new FileWriter( "second.xml" ) );
 
 
Then the output of second.xml will look like this...
 
<foo:bar xmlns:foo="someURI">
    something
</foo:bar>
 
 
Under the covers dom4j really just associates elements and attributes with QName objects which represent a local name and a Namespace. A Namespace object consists of just a prefix and a URI.
 
Which namespaces that are 'declared' depends on the document; unnecessary namespace declarations are ignored.
 
So in many ways the declaredNamespaces() method can returns a worst-case list of the namespaces that *may* be declared, though some of those declarations might be filtered out if they are already declared by a parent element.
 
e.g.
 
if this document were round tripped in dom4j...
 
<foo:bar xmlns:foo="someURI">
    <foo:x xmlns:foo="someURI"/>
</foo:bar>
 
it would come out like this...
 
<foo:bar xmlns:foo="someURI">
    <foo:x/>
</foo:bar>
 
Since the second namespace declaration is unnecessary.
 
Does the above all make sense and seem reasonable to you?
 
If it does, then maybe we should deprecate the declaredNamespaces() method as its a bit misleading. An Element may have a Namespace and may have additional Namespaces but it depends on its parents as to whether it will output those declartions when streaming itself to text, SAX or DOM.

James
----- Original Message -----
Sent: Friday, November 23, 2001 10:15 AM
Subject: [dom4j-dev] declaredNamespaces containing the element's namespace

Hi,

Is there a good reason why declaredNamespaces() method in AbstractElement includes the result of getNamespace() (if the namespace URI is not empty)? I would expect the declared namespaces to be only the namespaces explicitly declared on the element, and not for example the default namespace.

I suggest we either change this behaviour or the javadoc :)

Cheers,

-- Steen

/**
 * Steen Lehmann - <mailto:[EMAIL PROTECTED]>
 * Senior Software Engineer (R&D), SilverStream Software
 * <http://www.silverstream.com>
 */

Reply via email to