Yate
XmlSaxParser Class Reference

Serial Access XML Parser. More...

#include <yatexml.h>

Inheritance diagram for XmlSaxParser:
DebugEnabler XmlDomParser

Public Types

enum  Error {
  NoError = 0 , NotWellFormed , Unknown , IOError ,
  ElementParse , ReadElementName , InvalidElementName , ReadingAttributes ,
  CommentParse , DeclarationParse , DefinitionParse , CDataParse ,
  ReadingEndTag , Incomplete , InvalidEncoding , UnsupportedEncoding ,
  UnsupportedVersion
}
 
enum  Type {
  None = 0 , Text = 1 , CData = 2 , Element = 3 ,
  Doctype = 4 , Comment = 5 , Declaration = 6 , Instruction = 7 ,
  EndTag = 8 , Special = 9
}
 

Public Member Functions

virtual ~XmlSaxParser ()
 
unsigned int offset () const
 
unsigned int row () const
 
unsigned int column () const
 
const Stringbuffer () const
 
bool parse (const char *data)
 
bool completeText ()
 
Error error ()
 
bool setError (Error error, XmlChild *child=0)
 
const char * getError (const char *defVal="Xml error")
 
Type unparsed ()
 
void setUnparsed (Type id)
 
virtual void reset ()
 
const StringgetBuffer () const
 
- Public Member Functions inherited from DebugEnabler
 DebugEnabler (int level=TelEngine::debugLevel(), bool enabled=true)
 
int debugLevel () const
 
int debugLevel (int level)
 
bool debugEnabled () const
 
void debugEnabled (bool enable)
 
const char * debugName () const
 
bool debugAt (int level) const
 
bool debugChained () const
 
void debugChain (const DebugEnabler *chain=0)
 
void debugCopy (const DebugEnabler *original=0)
 
void debugSet (const char *desc)
 

Static Public Member Functions

static const char * getError (int code, const char *defVal="Xml error")
 
static bool blank (char c)
 
static bool checkFirstNameCharacter (unsigned char ch)
 
static bool checkDataChar (unsigned char c)
 
static bool checkNameCharacter (unsigned char ch)
 
static bool validTag (const String &buf)
 
static Stringescape (String &buf, const String &text)
 
static bool unEscape (String &text, String *error, bool *found=0)
 
static bool unEscape (String &text, const char *str, unsigned int len, String *error, bool inText=false, bool *found=0)
 

Static Public Attributes

static const TokenDict s_errorString []
 
static const XmlEscape s_escape []
 

Protected Member Functions

 XmlSaxParser (const char *name="XmlSaxParser")
 
bool parseInstruction ()
 
bool parseCData ()
 
bool parseComment ()
 
bool parseElement ()
 
bool parseDeclaration ()
 
bool parseSpecial ()
 
bool parseEndTag ()
 
bool parseDoctype ()
 
bool auxParse ()
 
void unEscape (String &text)
 
void skipBlanks ()
 
bool badCharacter (char c)
 
void resetError ()
 
void resetParsed ()
 
StringextractName (bool &empty)
 
NamedStringgetAttribute ()
 
virtual void gotComment (const String &text)
 
virtual void gotProcessing (const NamedString &instr)
 
virtual void gotDeclaration (const NamedList &decl)
 
virtual void gotText (const String &text)
 
virtual void gotCdata (const String &data)
 
virtual void gotElement (const NamedList &element, bool empty)
 
virtual void endElement (const String &name)
 
virtual void gotDoctype (const String &doc)
 
virtual bool completed ()
 
bool processElement (NamedList &list, bool empty)
 
bool processText (String &text)
 
- Protected Member Functions inherited from DebugEnabler
void debugName (const char *name)
 

Protected Attributes

unsigned int m_offset
 
unsigned int m_row
 
unsigned int m_column
 
Error m_error
 
String m_buf
 
NamedList m_parsed
 
Type m_unparsed
 

Detailed Description

Serial Access XML Parser.

A Serial Access Parser (SAX) for arbitrary XML data

Constructor & Destructor Documentation

◆ ~XmlSaxParser()

virtual ~XmlSaxParser ( )
virtual

Destructor

◆ XmlSaxParser()

XmlSaxParser ( const char * name = "XmlSaxParser")
protected

Constructor

Parameters
nameDebug name

Member Function Documentation

◆ auxParse()

bool auxParse ( )
protected

Parse an unfinished xml object. Extracts the parsed string from buffer if returns true

Returns
True if the object was parsed successfully

◆ badCharacter()

bool badCharacter ( char c)
inlineprotected

Check if a character is an angle bracket

Parameters
cThe character to verify
Returns
True if c is an angle bracket

◆ blank()

static bool blank ( char c)
inlinestatic

Check if the given character is blank

Parameters
cThe character to verify
Returns
True if c is blank

◆ buffer()

const String & buffer ( ) const
inline

Retrieve the parser's buffer

Returns
The parser's buffer

References XmlSaxParser::m_buf.

◆ checkDataChar()

static bool checkDataChar ( unsigned char c)
static

Check if the given character is in the range allowed for an xml char

Parameters
cThe character to check
Returns
True if the character is in range

◆ checkFirstNameCharacter()

static bool checkFirstNameCharacter ( unsigned char ch)
inlinestatic

Verify if the given character is in the range allowed to be first character from a xml tag

Parameters
chThe character to check
Returns
True if the character is in range

Referenced by XmlSaxParser::checkNameCharacter().

◆ checkNameCharacter()

static bool checkNameCharacter ( unsigned char ch)
inlinestatic

Verify if the given character is in the range allowed for a xml name

Parameters
chThe character to check
Returns
True if the character is in range

References XmlSaxParser::checkFirstNameCharacter().

◆ column()

unsigned int column ( ) const
inline

Get the column where the parser has found an error

Returns
The column number

References XmlSaxParser::m_column.

◆ completed()

virtual bool completed ( )
inlineprotectedvirtual

Callback method. Is called to check if we have an incomplete element. Default implementation returns always true

Returns
True

Reimplemented in XmlDomParser.

◆ completeText()

bool completeText ( )

Process incomplete text if the parser is completed. This method should be called to complete text after all data was pushed into the parser

Returns
True if all data was successfully parsed

◆ endElement()

virtual void endElement ( const String & name)
inlineprotectedvirtual

Callback method. Is called when a end tag was successfully parsed. Default implementation does nothing

Parameters
nameThe end tag name

Reimplemented in XmlDomParser.

◆ error()

Error error ( )
inline

Get the error code found while parsing

Returns
Error code

References XmlSaxParser::m_error.

Referenced by XmlSaxParser::unEscape().

◆ escape()

static String & escape ( String & buf,
const String & text )
static

XmlEscape the given text

Parameters
bufDestination buffer
textThe text to escape
Returns
Destination buffer reference

◆ extractName()

String * extractName ( bool & empty)
protected

Extract the name of an element or instruction

Returns
The extracted string or 0

◆ getAttribute()

NamedString * getAttribute ( )
protected

Extract an attribute

Returns
The attribute value or 0

◆ getBuffer()

const String & getBuffer ( ) const
inline
Returns
The internal buffer

References XmlSaxParser::m_buf.

◆ getError() [1/2]

const char * getError ( const char * defVal = "Xml error")
inline

Retrieve the error string associated with current error status

Parameters
defValValue to return if not found
Returns
The error string

References XmlSaxParser::getError(), and XmlSaxParser::m_error.

Referenced by XmlSaxParser::getError().

◆ getError() [2/2]

static const char * getError ( int code,
const char * defVal = "Xml error" )
inlinestatic

Retrieve the error string associated with a given error code

Parameters
codeCode of the error to look up
defValValue to return if not found
Returns
The error string

References XmlSaxParser::s_errorString.

◆ gotCdata()

virtual void gotCdata ( const String & data)
inlineprotectedvirtual

Callback method. Is called when a CData section was successfully parsed. Default implementation does nothing

Parameters
dataThe CData content

Reimplemented in XmlDomParser.

◆ gotComment()

virtual void gotComment ( const String & text)
inlineprotectedvirtual

Callback method. Is called when a comment was successfully parsed. Default implementation does nothing

Parameters
textThe comment content

Reimplemented in XmlDomParser.

◆ gotDeclaration()

virtual void gotDeclaration ( const NamedList & decl)
inlineprotectedvirtual

Callback method. Is called when a declaration was successfully parsed. Default implementation does nothing

Parameters
declThe declaration content

Reimplemented in XmlDomParser.

◆ gotDoctype()

virtual void gotDoctype ( const String & doc)
inlineprotectedvirtual

Callback method. Is called when a doctype was successfully parsed. Default implementation does nothing

Parameters
docThe doctype content

Reimplemented in XmlDomParser.

◆ gotElement()

virtual void gotElement ( const NamedList & element,
bool empty )
inlineprotectedvirtual

Callback method. Is called when an element was successfully parsed. Default implementation does nothing

Parameters
elementThe element content
emptyTrue if the element does not have attributes

Reimplemented in XmlDomParser.

◆ gotProcessing()

virtual void gotProcessing ( const NamedString & instr)
inlineprotectedvirtual

Callback method. Is called when an instruction was successfully parsed. Default implementation does nothing

Parameters
instrThe instruction content

Reimplemented in XmlDomParser.

◆ gotText()

virtual void gotText ( const String & text)
inlineprotectedvirtual

Callback method. Is called when a text was successfully parsed. Default implementation does nothing

Parameters
textThe text content

Reimplemented in XmlDomParser.

◆ offset()

unsigned int offset ( ) const
inline

Get the number of bytes successfully parsed

Returns
The number of bytes successfully parsed

References XmlSaxParser::m_offset.

◆ parse()

bool parse ( const char * data)

Parse a given string

Parameters
dataThe data to parse
Returns
True if all data was successfully parsed

◆ parseCData()

bool parseCData ( )
protected

Parse a CData section form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the CData section was parsed successfully

◆ parseComment()

bool parseComment ( )
protected

Parse a comment form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the comment was parsed successfully

◆ parseDeclaration()

bool parseDeclaration ( )
protected

Parse a declaration form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the declaration was parsed successfully

◆ parseDoctype()

bool parseDoctype ( )
protected

Parse a doctype form the main buffer. Extracts the parsed string from buffer if returns true. Warning: This is a stub implementation

Returns
True if the doctype was parsed successfully

◆ parseElement()

bool parseElement ( )
protected

Parse an element form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the element was parsed successfully

◆ parseEndTag()

bool parseEndTag ( )
protected

Parse an endtag form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the endtag was parsed successfully

◆ parseInstruction()

bool parseInstruction ( )
protected

Parse an instruction form the main buffer. Extracts the parsed string from buffer if returns true

Returns
True if the instruction was parsed successfully

◆ parseSpecial()

bool parseSpecial ( )
protected

Helper method to classify the Xml objects starting with "<!" sequence. Extracts the parsed string from buffer if returns true

Returns
True if a corresponding xml object was found and parsed successfully

◆ processElement()

bool processElement ( NamedList & list,
bool empty )
protected

Calls gotElement() and eset parsed on success

Parameters
listThe list element and its attributes
emptyTrue if the element does not have attributes
Returns
True if there is no error

◆ processText()

bool processText ( String & text)
protected

Unescape text, call gotText() and reset parsed on success

Parameters
textThe text to process
Returns
True if there is no error

◆ reset()

virtual void reset ( )
virtual

Reset error flag

Reimplemented in XmlDomParser.

◆ resetError()

void resetError ( )
inlineprotected

Reset the error

References XmlSaxParser::m_error.

◆ resetParsed()

void resetParsed ( )
inlineprotected

Reset parsed value and parameters

References String::clear(), NamedList::clearParams(), and XmlSaxParser::m_parsed.

◆ row()

unsigned int row ( ) const
inline

Get the row where the parser has found an error

Returns
The row number

References XmlSaxParser::m_row.

◆ setError()

bool setError ( Error error,
XmlChild * child = 0 )

Set the error code and destroys a child if error code is not NoError

Parameters
errorThe error found
childChild to destroy
Returns
False on error

◆ setUnparsed()

void setUnparsed ( Type id)
inline

Set the last xml type that we were parsing, but we have not finished

Parameters
idThe xml type that we haven't finish to parse

References XmlSaxParser::m_unparsed.

◆ skipBlanks()

void skipBlanks ( )
protected

Remove blank characters from the begining of the buffer

◆ unEscape() [1/3]

void unEscape ( String & text)
protected

Unescape the given text. Handled: &lt; &gt; &apos; &quot; &amp; &#DecimalNumber; &#xHexNumber;

Parameters
textThe requested text to unescape

◆ unEscape() [2/3]

static bool unEscape ( String & text,
const char * str,
unsigned int len,
String * error,
bool inText = false,
bool * found = 0 )
static

Unescape the given text. Handled: &lt; &gt; &apos; &quot; &amp; &#DecimalNumber; &#xHexNumber;

Parameters
textThe requested text to unescape
strInput buffer
lenInput buffer length
inTextUse destination text during unescape. If enabled the destination text may be incomplete on failure. The method will use a temporary buffer if disabled This parameter is ignored and handled as 'false' if 'str' points to destination string's buffer
errorDestination for error string
foundOptional flag to be set if unescape was found
Returns
True on success, false otherwise

◆ unEscape() [3/3]

static bool unEscape ( String & text,
String * error,
bool * found = 0 )
inlinestatic

Unescape the given text. Handled: &lt; &gt; &apos; &quot; &amp; &#DecimalNumber; &#xHexNumber;

Parameters
textThe requested text to unescape
errorDestination for error string
foundOptional flag to be set if unescape was found
Returns
True on success, false otherwise

References String::c_str(), XmlSaxParser::error(), String::length(), and XmlSaxParser::unEscape().

Referenced by XmlSaxParser::unEscape().

◆ unparsed()

Type unparsed ( )
inline
Returns
The last xml type that we were parsing, but we have not finished

References XmlSaxParser::m_unparsed.

◆ validTag()

static bool validTag ( const String & buf)
static

Check if a given string is a valid xml tag name

Parameters
bufThe string to check
Returns
True if the string is a valid xml tag name

Member Data Documentation

◆ m_buf

String m_buf
protected

The main buffer

Referenced by XmlSaxParser::buffer(), and XmlSaxParser::getBuffer().

◆ m_column

unsigned int m_column
protected

The column where the parser was stop

Referenced by XmlSaxParser::column().

◆ m_error

Error m_error
protected

The error code found while parsing data

Referenced by XmlSaxParser::error(), XmlSaxParser::getError(), and XmlSaxParser::resetError().

◆ m_offset

unsigned int m_offset
protected

The offset where the parser was stop

Referenced by XmlSaxParser::offset().

◆ m_parsed

NamedList m_parsed
protected

The parser data holder. Keeps the parsed data when an incomplete xml object is found

Referenced by XmlSaxParser::resetParsed().

◆ m_row

unsigned int m_row
protected

The row where the parser was stop

Referenced by XmlSaxParser::row().

◆ m_unparsed

Type m_unparsed
protected

The last parsed xml object code

Referenced by XmlSaxParser::setUnparsed(), and XmlSaxParser::unparsed().

◆ s_errorString

const TokenDict s_errorString[]
static

Errors dictionary

Referenced by XmlSaxParser::getError().

◆ s_escape

const XmlEscape s_escape[]
static

Escaped strings dictionary


The documentation for this class was generated from the following file: