No XML Declaration when serializing

RESOLVED WONTFIX

Status

()

Core
Serializers
RESOLVED WONTFIX
12 years ago
15 days ago

People

(Reporter: Bruno Vernay, Unassigned)

Tracking

Trunk
Points:
---
Bug Flags:
blocking1.9 -

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b5) Gecko/20051103 Flock/0.4 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b5) Gecko/20051103 Flock/0.4 Firefox/1.0+

When creating an XML document with Javascript, there is only a dirty hack to add an XML Declaration to it.

Reproducible: Always




    var doc = document.implementation.createDocument("", "", null);
    var rootElem = doc.createElement("toto");
    rootElem.setAttribute("version", "12334");
    doc.appendChild(rootElem);
    var serializer = new XMLSerializer();
    serializer.serializeToStream(doc, foStream, "UTF-8");
Result in no XML Declarations (there should be one.)

Dirty hack :
   var piElem = doc.createProcessingInstruction("xml", "version='1.0'
encoding='UTF8'");
...
    doc.appendChild(rootElem);
    doc.insertBefore(piElem, rootElem);

Note :
 - you can claim UTF-8 and encode in ISO-8859-1
 - a XML Declaration is not a Processing Instruction

See : http://groups.google.com/group/netscape.public.mozilla.xml/browse_thread/thread/f7860c1d53fcfcad/06741114303b461a#06741114303b461a
(Reporter)

Updated

12 years ago
Component: General → DOM: Load and Save
Product: Firefox → Core
Version: unspecified → 1.8 Branch
(Reporter)

Updated

12 years ago
Severity: enhancement → normal
Version: 1.8 Branch → Trunk
Assignee: nobody → general
QA Contact: general → ian
So yeah.  The DOM doesn't allow specifying the info in the XML declaration at document creation time, sadly.

But really, the main issue here is the encoding problem.  The current setup in nsXMLContentSerializer::AppendDocumentStart overloads the version to see whether there was a declaration or not.

I think we should do the following:

1)  Change nsIDocument::GetXMLDeclaration to always output the version, etc and
    return a boolean indicating whether there was an actual declaration.
2)  If serializing to UTF8 and there was no declaration, we should continue not
    producing a declaration, imo.
3)  If serializing to some other charset we MUST produce a declaration to create
    valid XML.
4)  Documents created via createDocument() should have
    XML_DECLARATION_BITS_DECLARATION_EXISTS set.

Thoughts?
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: blocking1.9?
Not a blocker.
Flags: blocking1.9? → blocking1.9-
Assignee: general → nobody
QA Contact: ian → general

Updated

6 years ago
Component: DOM: Other → Serializers
QA Contact: general → dom-to-text

Comment 3

15 days ago
We should always serialize UTF-8 (when it concerns bytes) so I don't think we need to fix this.
Status: NEW → RESOLVED
Last Resolved: 15 days ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.