[mapguide-commits] r8827 - sandbox/jng/clean_json/Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Nov 11 05:59:25 PST 2015


Author: jng
Date: 2015-11-11 05:59:25 -0800 (Wed, 11 Nov 2015)
New Revision: 8827

Modified:
   sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp
Log:
De-arrayify single-cardinality element nodes when CLEAN=1 and output format is JSON

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2015-11-11 13:35:40 UTC (rev 8826)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2015-11-11 13:59:25 UTC (rev 8827)
@@ -196,10 +196,17 @@
         string textContent;
         MgUtil::WideCharToMultiByte(X2W(node->getTextContent()), textContent);
 
-        // Write the text as a single array element
-        m_jsonDoc.BeginArray(1, nodeName);
-        m_jsonDoc.SetArrayValue(0, textContent);
-        m_jsonDoc.EndArray();
+        if (bClean)
+        {
+            m_jsonDoc.AddAttribute(nodeName, textContent);
+        }
+        else
+        {
+            // Write the text as a single array element
+            m_jsonDoc.BeginArray(1, nodeName);
+            m_jsonDoc.SetArrayValue(0, textContent);
+            m_jsonDoc.EndArray();
+        }
         return;
     }
     else if (nodeType == DOMNode::ELEMENT_NODE)
@@ -224,10 +231,17 @@
                     MgUtil::WideCharToMultiByte(X2W(childNode->getTextContent()), textContent);
                     if (this->ValidateTextContent(textContent))
                     {
-                        // Write the text as a single array element
-                        m_jsonDoc.BeginArray(1, nodeName);
-                        m_jsonDoc.SetArrayValue(0, textContent);
-                        m_jsonDoc.EndArray();
+                        if (bClean)
+                        {
+                            m_jsonDoc.Add(nodeName, textContent);
+                        }
+                        else
+                        {
+                            // Write the text as a single array element
+                            m_jsonDoc.BeginArray(1, nodeName);
+                            m_jsonDoc.SetArrayValue(0, textContent);
+                            m_jsonDoc.EndArray();
+                        }
                     }
                     return;
                 }



More information about the mapguide-commits mailing list