Author: borisk
Date: Tue Sep 16 06:15:25 2008
New Revision: 695864
URL: http://svn.apache.org/viewvc?rev=695864&view=rev
Log:
Avoid pretty-printing comments only in text-only nodes.
Modified:
xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp?rev=695864&r1=695863&r2=695864&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp Tue Sep 16
06:15:25 2008
@@ -1145,6 +1145,47 @@
if (checkFilter(nodeToWrite) != DOMNodeFilter::FILTER_ACCEPT)
break;
+ // Figure out if we want pretty-printing for this comment.
+ // If this comment node does not have any element siblings
+ // (i.e., it is a text node) then we don't want to add any
+ // whitespaces since that might be significant to the
+ // application. Otherwise we want pretty-printing.
+ //
+
+ bool pretty = (level == 0); // Document-level comments.
+
+ if (!pretty)
+ {
+ // See if we have any element siblings.
+ //
+ const DOMNode* s = nodeToWrite->getNextSibling ();
+
+ while (s != 0 && s->getNodeType () != DOMNode::ELEMENT_NODE)
+ s = s->getNextSibling ();
+
+ if (s != 0)
+ pretty = true;
+ else
+ {
+ s = nodeToWrite->getPreviousSibling ();
+
+ while (s != 0 && s->getNodeType () != DOMNode::ELEMENT_NODE)
+ s = s->getPreviousSibling ();
+
+ if (s != 0)
+ pretty = true;
+ }
+ }
+
+ if (pretty)
+ {
+ if(level == 1 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
+ printNewLine();
+
+ printNewLine();
+ printIndent(level);
+ }
+
TRY_CATCH_THROW
(
*fFormatter << XMLFormatter::NoEscapes << gStartComment
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]