From c1f86117f0abc84de0ac10495417af8ef4d69ab7 Mon Sep 17 00:00:00 2001 From: marian Date: Thu, 12 Apr 2018 12:38:59 +0000 Subject: [PATCH] Added extra parameter to XmlDocument::saveFile to allow saving flat documents. git-svn-id: http://voip.null.ro/svn/yate@6310 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/XML.cpp | 8 +++++--- yatexml.h | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/engine/XML.cpp b/engine/XML.cpp index 5a3014d7..5b927983 100644 --- a/engine/XML.cpp +++ b/engine/XML.cpp @@ -1639,7 +1639,7 @@ XmlSaxParser::Error XmlDocument::loadFile(const char* file, int* error) // Save this xml document in a file int XmlDocument::saveFile(const char* file, bool esc, const String& indent, - bool completeOnly) const + bool completeOnly, const char* eoln) const { if (!file) file = m_file; @@ -1648,11 +1648,13 @@ int XmlDocument::saveFile(const char* file, bool esc, const String& indent, File f; int err = 0; if (f.openPath(file,true,false,true,false)) { - String eol("\r\n"); + String eol(eoln); + if (eoln && !eol) + eol = "\r\n"; write(f,esc,eol,indent,completeOnly); err = f.error(); // Add an empty line - if (err >= 0) + if (err >= 0 && eol) f.writeData((void*)eol.c_str(),eol.length()); } else diff --git a/yatexml.h b/yatexml.h index f43d53c2..889f0593 100644 --- a/yatexml.h +++ b/yatexml.h @@ -550,12 +550,16 @@ public: /** * Append a new child of this XmlParent, release the object on failure * @param child The child to append + * @param code Optional pointr to error code to be filled on failure * @return The child on success, 0 on failure */ - inline XmlChild* addChildSafe(XmlChild* child) { + inline XmlChild* addChildSafe(XmlChild* child, XmlSaxParser::Error* code = 0) { XmlSaxParser::Error err = addChild(child); - if (err != XmlSaxParser::NoError) + if (err != XmlSaxParser::NoError) { TelEngine::destruct(child); + if (code) + *code = err; + } return child; } @@ -1010,6 +1014,15 @@ public: */ XmlDeclaration* declaration() const; + /** + * Retrieve XML fragment outside the root element + * @param before True to retrieve the fragment holding children before root element, + * false to retrieve children after root + * @return Requested fragment's reference + */ + inline const XmlFragment& getFragment(bool before) const + { return before ? m_beforeRoot : m_afterRoot; } + /** * Retrieve the root element * @param completed True to retrieve the root element if is not completed @@ -1084,10 +1097,12 @@ public: * @param escape True if the attributes values need to be escaped * @param indent Spaces for output * @param completeOnly True to build only if complete + * @param eoln End of line chars. Set it to NULL to ignore it. Empty string will be replaced by CR/LF * @return 0 on success, error code on failure */ int saveFile(const char* file = 0, bool escape = true, - const String& indent = String::empty(), bool completeOnly = true) const; + const String& indent = String::empty(), bool completeOnly = true, + const char* eoln = "\r\n") const; /** * Build a String from this XmlDocument