Fixed bug: always produce the same xml text regardless the way data is pushed into sax parser (sequentially or full). Added method to finalize incomplete xml text after pushing all data to sax parser. Added debug.

git-svn-id: http://yate.null.ro/svn/yate/trunk@4798 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2012-01-06 10:05:05 +00:00
parent 9ed27f23a0
commit 9efa390989
2 changed files with 53 additions and 13 deletions

View File

@ -167,21 +167,15 @@ bool XmlSaxParser::parse(const char* text)
auxData << m_buf.substr(0,len);
}
if (auxData.c_str()) { // We have an end of tag or another child is riseing
resetError();
unEscape(auxData);
gotText(auxData);
resetParsed();
if (error())
if (!processText(auxData))
return false;
m_buf = m_buf.substr(len);
len = 0;
auxData = "";
}
skipBlanks();
len = 0;
if (!m_buf.at(len + 1))
char auxCar = m_buf.at(1);
if (!auxCar)
return setError(Incomplete);
char auxCar = m_buf.at(len + 1);
if (auxCar == '?') {
m_buf = m_buf.substr(2);
if (!parseInstruction())
@ -206,10 +200,14 @@ bool XmlSaxParser::parse(const char* text)
if (!parseElement())
return false;
}
if (!completed()) {
// We have an element that is not complete
auxData << m_buf;
m_parsed.assign(auxData);
// Incomplete text
if ((unparsed() == None || unparsed() == Text) && (auxData || m_buf)) {
if (!auxData)
m_parsed.assign(m_buf);
else {
auxData << m_buf;
m_parsed.assign(auxData);
}
m_buf = "";
setUnparsed(Text);
return setError(Incomplete);
@ -220,9 +218,19 @@ bool XmlSaxParser::parse(const char* text)
}
m_buf = "";
resetParsed();
setUnparsed(None);
return true;
}
// Process incomplete text
bool XmlSaxParser::completeText()
{
if (!completed() || unparsed() != Text || error() != Incomplete)
return error() == NoError;
String tmp = m_parsed;
return processText(tmp);
}
// Parse an unfinished xml object
bool XmlSaxParser::auxParse()
{
@ -583,6 +591,7 @@ bool XmlSaxParser::parseComment()
// Parse an element form the main buffer
bool XmlSaxParser::parseElement()
{
XDebug(this,DebugAll,"XmlSaxParser::parseElement() buf len=%u [%p]",m_buf.length(),this);
if (!m_buf.c_str()) {
setUnparsed(Element);
return setError(Incomplete);
@ -1064,6 +1073,22 @@ bool XmlSaxParser::processElement(NamedList& list, bool empty)
return false;
}
// Calls gotText() and reset parsed on success
bool XmlSaxParser::processText(String& text)
{
resetError();
unEscape(text);
if (!error())
gotText(text);
else
setUnparsed(Text);
if (!error()) {
resetParsed();
setUnparsed(None);
}
return error() == NoError;
}
/*
* XmlDomPareser

View File

@ -153,6 +153,14 @@ public:
*/
bool parse(const char* data);
/**
* Process incomplete text if the parser is completed.
* This method should be called to complete text after
* all data was pushed into the parser
* @return True if all data was successfully parsed
*/
bool completeText();
/**
* Get the error code found while parsing
* @return Error code
@ -460,6 +468,13 @@ protected:
*/
bool processElement(NamedList& list, bool empty);
/**
* Unescape text, call gotText() and reset parsed on success
* @param text The text to process
* @return True if there is no error
*/
bool processText(String& text);
/**
* The offset where the parser was stop
*/