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
This commit is contained in:
parent
2c241d279f
commit
c1f86117f0
|
@ -1639,7 +1639,7 @@ XmlSaxParser::Error XmlDocument::loadFile(const char* file, int* error)
|
||||||
|
|
||||||
// Save this xml document in a file
|
// Save this xml document in a file
|
||||||
int XmlDocument::saveFile(const char* file, bool esc, const String& indent,
|
int XmlDocument::saveFile(const char* file, bool esc, const String& indent,
|
||||||
bool completeOnly) const
|
bool completeOnly, const char* eoln) const
|
||||||
{
|
{
|
||||||
if (!file)
|
if (!file)
|
||||||
file = m_file;
|
file = m_file;
|
||||||
|
@ -1648,11 +1648,13 @@ int XmlDocument::saveFile(const char* file, bool esc, const String& indent,
|
||||||
File f;
|
File f;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if (f.openPath(file,true,false,true,false)) {
|
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);
|
write(f,esc,eol,indent,completeOnly);
|
||||||
err = f.error();
|
err = f.error();
|
||||||
// Add an empty line
|
// Add an empty line
|
||||||
if (err >= 0)
|
if (err >= 0 && eol)
|
||||||
f.writeData((void*)eol.c_str(),eol.length());
|
f.writeData((void*)eol.c_str(),eol.length());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
21
yatexml.h
21
yatexml.h
|
@ -550,12 +550,16 @@ public:
|
||||||
/**
|
/**
|
||||||
* Append a new child of this XmlParent, release the object on failure
|
* Append a new child of this XmlParent, release the object on failure
|
||||||
* @param child The child to append
|
* @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
|
* @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);
|
XmlSaxParser::Error err = addChild(child);
|
||||||
if (err != XmlSaxParser::NoError)
|
if (err != XmlSaxParser::NoError) {
|
||||||
TelEngine::destruct(child);
|
TelEngine::destruct(child);
|
||||||
|
if (code)
|
||||||
|
*code = err;
|
||||||
|
}
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,6 +1014,15 @@ public:
|
||||||
*/
|
*/
|
||||||
XmlDeclaration* declaration() const;
|
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
|
* Retrieve the root element
|
||||||
* @param completed True to retrieve the root element if is not completed
|
* @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 escape True if the attributes values need to be escaped
|
||||||
* @param indent Spaces for output
|
* @param indent Spaces for output
|
||||||
* @param completeOnly True to build only if complete
|
* @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
|
* @return 0 on success, error code on failure
|
||||||
*/
|
*/
|
||||||
int saveFile(const char* file = 0, bool escape = true,
|
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
|
* Build a String from this XmlDocument
|
||||||
|
|
Loading…
Reference in New Issue