Added extra parameter to XmlDocument::saveFile to allow saving flat documents.

git-svn-id: http://yate.null.ro/svn/yate/trunk@6310 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2018-04-12 12:38:59 +00:00
parent 0461cfbdcb
commit 90993a34de
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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