xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bor...@apache.org
Subject svn commit: r695864 - /xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
Date Tue, 16 Sep 2008 13:15:26 GMT
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: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org


Mime
View raw message