removed nascent ST2052-1 support pending completion
[asdcplib.git] / src / KM_xml.cpp
index ad31ce894448a5323988ce9ee8db9ee65c90ea92..121f0a6ad02437d1a17b3b81dc596a51387e2f8a 100644 (file)
@@ -186,10 +186,10 @@ Kumu::XMLElement::AddComment(const char* value)
 
 //
 void
-Kumu::XMLElement::Render(std::string& outbuf) const
+Kumu::XMLElement::Render(std::string& outbuf, const bool& pretty) const
 {
   outbuf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-  RenderElement(outbuf, 0);
+  RenderElement(outbuf, 0, pretty);
 }
 
 //
@@ -202,15 +202,18 @@ add_spacer(std::string& outbuf, i32_t depth)
 
 //
 void
-Kumu::XMLElement::RenderElement(std::string& outbuf, ui32_t depth) const
+Kumu::XMLElement::RenderElement(std::string& outbuf, const ui32_t& depth, const bool& pretty) const
 {
-  add_spacer(outbuf, depth);
+  if ( pretty )
+    {
+      add_spacer(outbuf, depth);
+    }
 
   outbuf += "<";
   outbuf += m_Name;
 
   // render attributes
-  for ( Attr_i i = m_AttrList.begin(); i != m_AttrList.end(); i++ )
+  for ( Attr_i i = m_AttrList.begin(); i != m_AttrList.end(); ++i )
     {
       outbuf += " ";
       outbuf += (*i).name;
@@ -228,12 +231,19 @@ Kumu::XMLElement::RenderElement(std::string& outbuf, ui32_t depth) const
 
       // render body
       if ( m_Body.length() > 0 )
-       outbuf += m_Body;
+       {
+         outbuf += m_Body;
+       }
 
-      for ( Elem_i i = m_ChildList.begin(); i != m_ChildList.end(); i++ )
-       (*i)->RenderElement(outbuf, depth + 1);
+      for ( Elem_i i = m_ChildList.begin(); i != m_ChildList.end(); ++i )
+       {
+         (*i)->RenderElement(outbuf, depth + 1, pretty);
+       }
 
-      add_spacer(outbuf, depth);
+      if ( pretty )
+       {
+         add_spacer(outbuf, depth);
+       }
     }
   else if ( m_Body.length() > 0 )
     {
@@ -375,6 +385,20 @@ Kumu::XMLElement::ForgetChild(const XMLElement* element)
     }
 }
 
+//
+bool
+Kumu::XMLElement::ParseString(const ByteString& document)
+{
+  return ParseString((const char*)document.RoData(), document.Length());
+}
+
+//
+bool
+Kumu::XMLElement::ParseString(const std::string& document)
+{
+  return ParseString(document.c_str(), document.size());
+}
+
 
 //----------------------------------------------------------------------------------------------------
 
@@ -517,10 +541,10 @@ Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len)
 
   if ( ! XML_Parse(Parser, document, doc_len, 1) )
     {
-      XML_ParserFree(Parser);
       DefaultLogSink().Error("XML Parse error on line %d: %s\n",
                             XML_GetCurrentLineNumber(Parser),
                             XML_ErrorString(XML_GetErrorCode(Parser)));
+      XML_ParserFree(Parser);
       return false;
     }
 
@@ -976,7 +1000,7 @@ Kumu::StringIsXML(const char* document, ui32_t len)
 
 //
 bool
-Kumu::XMLElement::ParseString(const std::string& document)
+Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len)
 {
   DefaultLogSink().Error("Kumu compiled without XML parser support.\n");
   return false;