From 996c512d454952aa560573c2bb6a954e2d5b378a Mon Sep 17 00:00:00 2001
From: Gareth Reakes <gareth@apache.org>
Date: Mon, 24 Nov 2003 12:27:57 +0000
Subject: [PATCH] added in support for xml-declaration feature.

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175446 13f79535-47bb-0310-9956-ffa450edef68
---
 src/xercesc/dom/impl/DOMWriterImpl.cpp | 32 +++++++++++++++++---------
 src/xercesc/util/XMLUni.cpp            |  8 +++++++
 src/xercesc/util/XMLUni.hpp            |  2 ++
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/xercesc/dom/impl/DOMWriterImpl.cpp b/src/xercesc/dom/impl/DOMWriterImpl.cpp
index 08810c024..934a21bb7 100644
--- a/src/xercesc/dom/impl/DOMWriterImpl.cpp
+++ b/src/xercesc/dom/impl/DOMWriterImpl.cpp
@@ -57,6 +57,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.45  2003/11/24 12:27:57  gareth
+ * added in support for xml-declaration feature.
+ *
  * Revision 1.44  2003/11/24 11:10:58  gareth
  * Fix for bug 22917. Patch by Adam Heinz .
  *
@@ -232,6 +235,7 @@ static const int SPLIT_CDATA_SECTIONS_ID          = 0x5;
 static const int VALIDATION_ID                    = 0x6;
 static const int WHITESPACE_IN_ELEMENT_CONTENT_ID = 0x7;
 static const int BYTE_ORDER_MARK_ID               = 0x8;
+static const int XML_DECLARATIION                 = 0x9;
 
 //    feature                      true                       false
 // ================================================================================
@@ -259,7 +263,8 @@ static const bool  featuresSupported[] = {
     true,  true,  // split-cdata-sections
     false, true,  // validation
     true,  false, // whitespace-in-element-content
-    true,  true   // byte-order-mark
+    true,  true,   // byte-order-mark
+    true,  true   // xml-declaration
 };
 
 // default end-of-line sequence
@@ -509,6 +514,8 @@ DOMWriterImpl::DOMWriterImpl(MemoryManager* const manager)
     setFeature(VALIDATION_ID,                    false);
     setFeature(WHITESPACE_IN_ELEMENT_CONTENT_ID, true );
     setFeature(BYTE_ORDER_MARK_ID,               false);
+    setFeature(XML_DECLARATIION,                 true );
+
 }
 
 bool DOMWriterImpl::canSetFeature(const XMLCh* const featName
@@ -886,19 +893,19 @@ void DOMWriterImpl::processNode(const DOMNode* const nodeToWrite, int level)
             //[80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName
             //[32] SDDecl       ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
             //
-            // We always print out the xmldecl no matter whether it is
-            // present in the original XML instance document or not.
-            //
-            const XMLCh* versionNo = (docu->getVersion()) ? docu->getVersion() : gXMLDecl_ver10;
-            *fFormatter << gXMLDecl_VersionInfo << versionNo << gXMLDecl_separator;
 
-            // use the encoding resolved in initSession()
-            *fFormatter << gXMLDecl_EncodingDecl << fEncodingUsed << gXMLDecl_separator;
+            if (getFeature(XML_DECLARATIION)) {
+                const XMLCh* versionNo = (docu->getVersion()) ? docu->getVersion() : gXMLDecl_ver10;
+                *fFormatter << gXMLDecl_VersionInfo << versionNo << gXMLDecl_separator;
 
-            const XMLCh* st = (docu->getStandalone())? XMLUni::fgYesString : XMLUni::fgNoString;
-            *fFormatter << gXMLDecl_SDDecl << st << gXMLDecl_separator;
+                // use the encoding resolved in initSession()
+                *fFormatter << gXMLDecl_EncodingDecl << fEncodingUsed << gXMLDecl_separator;
 
-            *fFormatter << gXMLDecl_endtag;
+                const XMLCh* st = (docu->getStandalone())? XMLUni::fgYesString : XMLUni::fgNoString;
+                *fFormatter << gXMLDecl_SDDecl << st << gXMLDecl_separator;
+                
+                *fFormatter << gXMLDecl_endtag;
+            }
 
             DOMNodeSPtr child = nodeToWrite->getFirstChild();
             while( child != 0)
@@ -1455,6 +1462,9 @@ bool DOMWriterImpl::checkFeature(const XMLCh* const featName
         featureId = WHITESPACE_IN_ELEMENT_CONTENT_ID;
     else if (XMLString::equals(featName, XMLUni::fgDOMWRTBOM))
         featureId = BYTE_ORDER_MARK_ID;
+    else if (XMLString::equals(featName, XMLUni::fgDOMXMLDeclaration))
+        featureId = XML_DECLARATIION;
+
 
     //feature name not resolvable
     if (featureId == INVALID_FEATURE_ID)
diff --git a/src/xercesc/util/XMLUni.cpp b/src/xercesc/util/XMLUni.cpp
index 5d1a34b6f..527daea14 100644
--- a/src/xercesc/util/XMLUni.cpp
+++ b/src/xercesc/util/XMLUni.cpp
@@ -1388,6 +1388,14 @@ const XMLCh XMLUni::fgDOMWRTBOM[] =
     chLatin_m, chLatin_a, chLatin_r, chLatin_k, chNull
 };
 
+//xml-declaration
+const XMLCh XMLUni::fgDOMXMLDeclaration[] =
+{ 
+    chLatin_x, chLatin_m, chLatin_l, chDash, chLatin_d, chLatin_e, chLatin_c,
+    chLatin_l, chLatin_a, chLatin_r, chLatin_a, chLatin_t, chLatin_i, chLatin_o,
+    chLatin_n, chNull 
+};
+
 // en_US
 const char XMLUni::fgXercescDefaultLocale[] = "en_US";
 
diff --git a/src/xercesc/util/XMLUni.hpp b/src/xercesc/util/XMLUni.hpp
index fe3b7d07c..7b038c90a 100644
--- a/src/xercesc/util/XMLUni.hpp
+++ b/src/xercesc/util/XMLUni.hpp
@@ -288,6 +288,8 @@ public :
     static const XMLCh fgDOMWRTValidation[];
     static const XMLCh fgDOMWRTWhitespaceInElementContent[];
     static const XMLCh fgDOMWRTBOM[];
+    static const XMLCh fgDOMXMLDeclaration[];
+
 
     // Locale
     static const char  fgXercescDefaultLocale[];
-- 
GitLab