|
|
@ -17,7 +17,6 @@
|
|
|
|
#include "stdmisc.h"
|
|
|
|
#include "stdmisc.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "nel/misc/i_xml.h"
|
|
|
|
#include "nel/misc/i_xml.h"
|
|
|
|
#include "nel/misc/sstring.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef NL_DONT_USE_EXTERNAL_CODE
|
|
|
|
#ifndef NL_DONT_USE_EXTERNAL_CODE
|
|
|
|
|
|
|
|
|
|
|
@ -39,6 +38,10 @@ namespace NLMISC
|
|
|
|
|
|
|
|
|
|
|
|
const char SEPARATOR = ' ';
|
|
|
|
const char SEPARATOR = ' ';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CIXml::_ErrorString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CIXml::_LibXmlIntialized = false;
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
#define readnumber(dest,digits) \
|
|
|
|
#define readnumber(dest,digits) \
|
|
|
@ -124,7 +127,7 @@ void xmlGenericErrorFuncRead (void *ctx, const char *msg, ...)
|
|
|
|
// Get the error string
|
|
|
|
// Get the error string
|
|
|
|
string str;
|
|
|
|
string str;
|
|
|
|
NLMISC_CONVERT_VARGS (str, msg, NLMISC::MaxCStringSize);
|
|
|
|
NLMISC_CONVERT_VARGS (str, msg, NLMISC::MaxCStringSize);
|
|
|
|
((CIXml*)ctx)->_ErrorString += str;
|
|
|
|
CIXml::_ErrorString += str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
@ -134,7 +137,7 @@ bool CIXml::init (IStream &stream)
|
|
|
|
// Release
|
|
|
|
// Release
|
|
|
|
release ();
|
|
|
|
release ();
|
|
|
|
|
|
|
|
|
|
|
|
xmlInitParser();
|
|
|
|
initLibXml();
|
|
|
|
|
|
|
|
|
|
|
|
// Default : XML mode
|
|
|
|
// Default : XML mode
|
|
|
|
_BinaryStream = NULL;
|
|
|
|
_BinaryStream = NULL;
|
|
|
@ -190,12 +193,7 @@ bool CIXml::init (IStream &stream)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set error handler
|
|
|
|
|
|
|
|
_ErrorString.clear();
|
|
|
|
_ErrorString.clear();
|
|
|
|
xmlSetGenericErrorFunc (this, xmlGenericErrorFuncRead);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ask to get debug info
|
|
|
|
|
|
|
|
xmlLineNumbersDefault(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The parser context
|
|
|
|
// The parser context
|
|
|
|
_Parser = xmlCreatePushParserCtxt(NULL, NULL, buffer, 4, NULL);
|
|
|
|
_Parser = xmlCreatePushParserCtxt(NULL, NULL, buffer, 4, NULL);
|
|
|
@ -1068,6 +1066,7 @@ bool CIXml::getPropertyString (std::string &result, xmlNodePtr node, const std::
|
|
|
|
// Found
|
|
|
|
// Found
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1075,18 +1074,21 @@ bool CIXml::getPropertyString (std::string &result, xmlNodePtr node, const std::
|
|
|
|
|
|
|
|
|
|
|
|
int CIXml::getIntProperty(xmlNodePtr node, const std::string &property, int defaultValue)
|
|
|
|
int CIXml::getIntProperty(xmlNodePtr node, const std::string &property, int defaultValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CSString s;
|
|
|
|
std::string s;
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
|
|
|
|
bool b = getPropertyString(s, node, property);
|
|
|
|
|
|
|
|
|
|
|
|
b=getPropertyString(s,node,property);
|
|
|
|
if (!b)
|
|
|
|
if (b==false)
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
return defaultValue;
|
|
|
|
|
|
|
|
|
|
|
|
s=s.strip();
|
|
|
|
// remove leading and trailing spaces
|
|
|
|
sint val=s.atoi();
|
|
|
|
s = trim(s);
|
|
|
|
if (val==0 && s!="0")
|
|
|
|
|
|
|
|
|
|
|
|
sint val;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fromString(s, val) || (val == 0 && s != "0"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
nlwarning("bad integer value: %s",s.c_str());
|
|
|
|
nlwarning("Bad integer value: %s",s.c_str());
|
|
|
|
return defaultValue;
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1097,14 +1099,25 @@ int CIXml::getIntProperty(xmlNodePtr node, const std::string &property, int defa
|
|
|
|
|
|
|
|
|
|
|
|
double CIXml::getFloatProperty(xmlNodePtr node, const std::string &property, float defaultValue)
|
|
|
|
double CIXml::getFloatProperty(xmlNodePtr node, const std::string &property, float defaultValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CSString s;
|
|
|
|
std::string s;
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
|
|
|
|
bool b = getPropertyString(s, node, property);
|
|
|
|
|
|
|
|
|
|
|
|
b=getPropertyString(s,node,property);
|
|
|
|
if (!b)
|
|
|
|
if (b==false)
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
return defaultValue;
|
|
|
|
|
|
|
|
|
|
|
|
return s.strip().atof();
|
|
|
|
// remove leading and trailing spaces
|
|
|
|
|
|
|
|
s = trim(s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float val;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fromString(s, val))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning("Bad float value: %s", s.c_str());
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
@ -1112,10 +1125,10 @@ double CIXml::getFloatProperty(xmlNodePtr node, const std::string &property, flo
|
|
|
|
std::string CIXml::getStringProperty(xmlNodePtr node, const std::string &property, const std::string& defaultValue)
|
|
|
|
std::string CIXml::getStringProperty(xmlNodePtr node, const std::string &property, const std::string& defaultValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
std::string s;
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b=getPropertyString(s,node,property);
|
|
|
|
bool b = getPropertyString(s, node, property);
|
|
|
|
if (b==false)
|
|
|
|
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
return defaultValue;
|
|
|
|
return defaultValue;
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
return s;
|
|
|
@ -1141,9 +1154,43 @@ bool CIXml::getContentString (std::string &result, xmlNodePtr node)
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CIXml::initLibXml()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_LibXmlIntialized) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ErrorString.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set error handler
|
|
|
|
|
|
|
|
xmlSetGenericErrorFunc (NULL, xmlGenericErrorFuncRead);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LIBXML_TEST_VERSION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// an error occured during initialization
|
|
|
|
|
|
|
|
if (!_ErrorString.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw EXmlParsingError (_ErrorString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ask to get debug info
|
|
|
|
|
|
|
|
xmlLineNumbersDefault(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_LibXmlIntialized = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
void CIXml::releaseLibXml()
|
|
|
|
void CIXml::releaseLibXml()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!_LibXmlIntialized) return;
|
|
|
|
|
|
|
|
|
|
|
|
xmlCleanupParser();
|
|
|
|
xmlCleanupParser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_LibXmlIntialized = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CIXml::getErrorString()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _ErrorString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // NLMISC
|
|
|
|
} // NLMISC
|
|
|
|