Bug 126869 - serializeToString doesnt work on a DOMNode, only DOMDocument
Summary: serializeToString doesnt work on a DOMNode, only DOMDocument
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml ecma (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-06 23:29 UTC by Fredrik Johansson
Modified: 2006-06-29 11:49 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
testpage (1.26 KB, text/html)
2006-05-06 23:30 UTC, Fredrik Johansson
Details
[Patch], supports serialize a DOMNode as well as DOMDocument (1.47 KB, text/x-diff)
2006-06-12 18:31 UTC, Fredrik Johansson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fredrik Johansson 2006-05-06 23:29:17 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
Compiler:          g++ 4.02 (Kubuntu breezy) 
OS:                Linux

XMLSerializer.serializeToString(node);
returns undefined, in moz it does serialize the tree under node.

However if we provide the node.ownerDocument it serializes DOMDocument.

This is less usefull if we would want to make a cross browser innerXML function in ecmascript


I copied webcore's function in xmlserializer.cpp and it seems to work, however you are probably better suited to deside if it could get in kde3.5.3

Im sypplying a testcase for you.

Regards
Fredrik Johansson
Comment 1 Fredrik Johansson 2006-05-06 23:30:27 UTC
Created attachment 15954 [details]
testpage
Comment 2 Fredrik Johansson 2006-06-12 18:31:39 UTC
Created attachment 16573 [details]
[Patch], supports serialize a DOMNode as well as DOMDocument 

Attached a patch that makes this work on a kde3.5.x branch.

The ecma/xmlserializer.cpp code is a modified version from webcore.
The xml/dom_elementimpl.cpp code is my own.

Regards
Fredrik Johansson
Comment 3 Germain Garand 2006-06-29 11:49:56 UTC
SVN commit 556110 by ggarand:

apply patch from  Fredrik Johansson <fredrik@mumme.se>

make serializeToString work  DOMNodes

BUG: 126869 


 M  +4 -5      ecma/xmlserializer.cpp  
 M  +3 -0      xml/dom_elementimpl.cpp  


--- branches/KDE/3.5/kdelibs/khtml/ecma/xmlserializer.cpp #556109:556110
@@ -79,21 +79,20 @@
 	return Undefined();
       }
 
-      if (!args[0].toObject(exec).inherits(&DOMDocument::info)) {
+      if (!args[0].toObject(exec).inherits(&DOMNode::info)) {
 	return Undefined();
       }
 
-      DOM::Node docNode = static_cast<KJS::DOMDocument *>(args[0].toObject(exec).imp())->toNode();
-      DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(docNode.handle());
+      DOM::NodeImpl *node = static_cast<DOM::NodeImpl *>(static_cast<KJS::DOMNode *>(args[0].toObject(exec).imp())->toNode().handle());
 
-      if (!doc) {
+      if (!node) {
 	return Undefined();
       }
 
       QString body;
 
       try {
-	  body = doc->toString().string();
+	  body = node->toString().string();
       } catch(DOM::DOMException& e) {
 	  Object err = Error::create(exec, GeneralError, "Exception serializing document");
 	  exec->setException(err);
--- branches/KDE/3.5/kdelibs/khtml/xml/dom_elementimpl.cpp #556109:556110
@@ -836,6 +836,9 @@
 	result += "</";
 	result += tagName();
 	result += ">";
+    } else if (result.length() == 1) {
+	// ensure we dont get results like < /> can happen when serialize document
+        result = "";
     } else {
 	result += " />";
     }