Yate
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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)
 

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 void escape (String &buf, const String &text)
 

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

virtual ~XmlSaxParser ( )
virtual

Destructor

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

Constructor

Parameters
nameDebug name

Member Function Documentation

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
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
static bool blank ( char  c)
inlinestatic

Check if the given character is blank

Parameters
cThe character to verify
Returns
True if c is blank
const String& buffer ( ) const
inline

Retrieve the parser's buffer

Returns
The parser's buffer

References XmlSaxParser::m_buf.

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
static bool checkFirstNameCharacter ( unsigned char  ch)
static

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
static bool checkNameCharacter ( unsigned char  ch)
static

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
unsigned int column ( ) const
inline

Get the column where the parser has found an error

Returns
The column number

References XmlSaxParser::m_column.

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.

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
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 ( )
inline

Get the error code found while parsing

Returns
Error code

References XmlSaxParser::m_error.

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

XmlEscape the given text

Parameters
bufDestination buffer
textThe text to escape
String* extractName ( bool &  empty)
protected

Extract the name of an element or instruction

Returns
The extracted string or 0
NamedString* getAttribute ( )
protected

Extract an attribute

Returns
The attribute value or 0
const String& getBuffer ( ) const
inline
Returns
The internal buffer

References XmlSaxParser::m_buf.

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::m_error.

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 TelEngine::lookup(), and XmlSaxParser::s_errorString.

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.

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.

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.

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.

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.

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.

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.

unsigned int offset ( ) const
inline

Get the number of bytes successfully parsed

Returns
The number of bytes successfully parsed

References XmlSaxParser::m_offset.

bool parse ( const char *  data)

Parse a given string

Parameters
dataThe data to parse
Returns
True if all data was successfully parsed
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
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
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
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
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
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
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
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
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
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
virtual void reset ( )
virtual

Reset error flag

Reimplemented in XmlDomParser.

void resetError ( )
inlineprotected

Reset the error

References XmlSaxParser::m_error.

void resetParsed ( )
inlineprotected

Reset parsed value and parameters

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

unsigned int row ( ) const
inline

Get the row where the parser has found an error

Returns
The row number

References XmlSaxParser::m_row.

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

void skipBlanks ( )
protected

Remove blank characters from the begining of the buffer

void unEscape ( String text)
protected

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

Parameters
textThe requested text to unescape
Type unparsed ( )
inline
Returns
The last xml type that we were parsing, but we have not finished

References XmlSaxParser::m_unparsed.

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

String m_buf
protected

The main buffer

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

unsigned int m_column
protected

The column where the parser was stop

Referenced by XmlSaxParser::column().

Error m_error
protected

The error code found while parsing data

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

unsigned int m_offset
protected

The offset where the parser was stop

Referenced by XmlSaxParser::offset().

NamedList m_parsed
protected

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

Referenced by XmlSaxParser::resetParsed().

unsigned int m_row
protected

The row where the parser was stop

Referenced by XmlSaxParser::row().

Type m_unparsed
protected

The last parsed xml object code

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

const TokenDict s_errorString[]
static

Errors dictionary

Referenced by XmlSaxParser::getError().

const XmlEscape s_escape[]
static

Escaped strings dictionary


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