Re: XML Declaration

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>

Heikki Toivonen wrote:

> Given that there is no other way to create the processing instruction
> (right?), I would hate to "fix" this by making it impossible to create
> the processing instruction.

That sounds like some misunderstanding. In terms of the XML 
specification and it terms of the W3C DOM the XML declaration is not a 
processing instruction even if the markup delimiters are the same.
If you load XML from source and the W3C DOM is built then the XML 
declaration does not show up in the DOM as a child node at all, 
certainly not as a processing instruction node.
In DOM Level 3 core some info from the XML declaration should be exposed 
as properties of the document object, namely
   xmlVersion
     <http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-version>
   xmlEncoding
     <http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-encoding>
   xmlStandalone
   <http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-standalone>

The current problem in this thread is originally that XMLSerializer and 
its serialization methods do not seem to create an XML declaration when 
serializing a DOM document and that a "hack to fix that" by creating and 
inserting a processing instruction node in the DOM looking like an XML 
declaration when being serialized is possible.
But Jonas thinks that hack should not work and be fixed.
If Bruno is right that
   serializer.serializeToStream(doc, foStream, "ISO-8859-1")
does not create an XML declaration then I think the method should be 
fixed first to ensure an XML declaration properly declares the encoding 
the serialized markup has.

> Anybody know what you are supposed to do in DOM to create a processing
> instruction? 

Of course you can create a processing instruction with the method 
createProcessingInstruction.
The question however is how you can make sure serialization of a DOM 
tree has an XML declaration without needing the above "hack" of putting 
in a processing instruction in the DOM looking like the XML declaration 
when being serialized.
DOM Level 3 Load and Save for LSSerializer allows to set a property 
named xml-declaration to have one.
Only Opera (8.xy release versions and the version 9 preview) implement 
DOM Level 3 Load and Save but setting that property does not work so far
<http://home.arcor.de/martin.honnen/operaBugs/op9/DOMLevel3/LSSerializerXMLDeclaration1.html>


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.