Summary: | serializeToString doesnt work on a DOMNode, only DOMDocument | ||
---|---|---|---|
Product: | [Applications] konqueror | Reporter: | Fredrik Johansson <fredrik> |
Component: | khtml ecma | Assignee: | Konqueror Developers <konq-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: |
testpage
[Patch], supports serialize a DOMNode as well as DOMDocument |
Description
Fredrik Johansson
2006-05-06 23:29:17 UTC
Created attachment 15954 [details]
testpage
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
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 += " />"; } |