Yate
|
Serial Access XML Parser. More...
#include <yatexml.h>
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 String & | buffer () 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 String & | getBuffer () const |
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 () |
String * | extractName (bool &empty) |
NamedString * | getAttribute () |
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 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 |
Serial Access XML Parser.
A Serial Access Parser (SAX) for arbitrary XML data
virtual ~XmlSaxParser | ( | ) | [virtual] |
Destructor
XmlSaxParser | ( | const char * | name = "XmlSaxParser" | ) | [protected] |
Constructor
name | Debug name |
bool auxParse | ( | ) | [protected] |
Parse an unfinished xml object. Extracts the parsed string from buffer if returns true
bool badCharacter | ( | char | c | ) | [inline, protected] |
Check if a character is an angle bracket
c | The character to verify |
static bool blank | ( | char | c | ) | [inline, static] |
Check if the given character is blank
c | The character to verify |
static bool checkDataChar | ( | unsigned char | c | ) | [static] |
Check if the given character is in the range allowed for an xml char
c | The character to check |
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
ch | The character to check |
static bool checkNameCharacter | ( | unsigned char | ch | ) | [static] |
Verify if the given character is in the range allowed for a xml name
ch | The character to check |
unsigned int column | ( | ) | const [inline] |
Get the column where the parser has found an error
virtual bool completed | ( | ) | [inline, protected, virtual] |
Callback method. Is called to check if we have an incomplete element. Default implementation returns always 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
virtual void endElement | ( | const String & | name | ) | [inline, protected, virtual] |
Callback method. Is called when a end tag was successfully parsed. Default implementation does nothing
name | The end tag name |
Reimplemented in XmlDomParser.
Error error | ( | ) | [inline] |
Get the error code found while parsing
XmlEscape the given text
buf | Destination buffer |
text | The text to escape |
String* extractName | ( | bool & | empty | ) | [protected] |
Extract the name of an element or instruction
NamedString* getAttribute | ( | ) | [protected] |
Extract an attribute
Retrieve the error string associated with current error status
defVal | Value to return if not found |
References XmlSaxParser::getError().
Referenced by XmlSaxParser::getError().
Retrieve the error string associated with a given error code
code | Code of the error to look up |
defVal | Value to return if not found |
References TelEngine::lookup().
Callback method. Is called when a CData section was successfully parsed. Default implementation does nothing
data | The CData content |
Reimplemented in XmlDomParser.
virtual void gotComment | ( | const String & | text | ) | [inline, protected, virtual] |
Callback method. Is called when a comment was successfully parsed. Default implementation does nothing
text | The comment content |
Reimplemented in XmlDomParser.
virtual void gotDeclaration | ( | const NamedList & | decl | ) | [inline, protected, virtual] |
Callback method. Is called when a declaration was successfully parsed. Default implementation does nothing
decl | The declaration content |
Reimplemented in XmlDomParser.
virtual void gotDoctype | ( | const String & | doc | ) | [inline, protected, virtual] |
Callback method. Is called when a doctype was successfully parsed. Default implementation does nothing
doc | The doctype content |
Reimplemented in XmlDomParser.
virtual void gotElement | ( | const NamedList & | element, |
bool | empty | ||
) | [inline, protected, virtual] |
Callback method. Is called when an element was successfully parsed. Default implementation does nothing
element | The element content |
empty | True if the element does not have attributes |
Reimplemented in XmlDomParser.
virtual void gotProcessing | ( | const NamedString & | instr | ) | [inline, protected, virtual] |
Callback method. Is called when an instruction was successfully parsed. Default implementation does nothing
instr | The instruction content |
Reimplemented in XmlDomParser.
Callback method. Is called when a text was successfully parsed. Default implementation does nothing
text | The text content |
Reimplemented in XmlDomParser.
unsigned int offset | ( | ) | const [inline] |
Get the number of bytes successfully parsed
bool parse | ( | const char * | data | ) |
Parse a given string
data | The data to parse |
bool parseCData | ( | ) | [protected] |
Parse a CData section form the main buffer. Extracts the parsed string from buffer if returns true
bool parseComment | ( | ) | [protected] |
Parse a comment form the main buffer. Extracts the parsed string from buffer if returns true
bool parseDeclaration | ( | ) | [protected] |
Parse a declaration form the main buffer. Extracts the parsed string from buffer if returns true
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
bool parseElement | ( | ) | [protected] |
Parse an element form the main buffer. Extracts the parsed string from buffer if returns true
bool parseEndTag | ( | ) | [protected] |
Parse an endtag form the main buffer. Extracts the parsed string from buffer if returns true
bool parseInstruction | ( | ) | [protected] |
Parse an instruction form the main buffer. Extracts the parsed string from buffer if returns true
bool parseSpecial | ( | ) | [protected] |
Helper method to classify the Xml objects starting with "<!" sequence. Extracts the parsed string from buffer if returns true
bool processElement | ( | NamedList & | list, |
bool | empty | ||
) | [protected] |
Calls gotElement() and eset parsed on success
list | The list element and its attributes |
empty | True if the element does not have attributes |
bool processText | ( | String & | text | ) | [protected] |
Unescape text, call gotText() and reset parsed on success
text | The text to process |
virtual void reset | ( | ) | [virtual] |
Reset error flag
Reimplemented in XmlDomParser.
void resetError | ( | ) | [inline, protected] |
Reset the error
void resetParsed | ( | ) | [inline, protected] |
Reset parsed value and parameters
unsigned int row | ( | ) | const [inline] |
Get the row where the parser has found an error
Set the error code and destroys a child if error code is not NoError
error | The error found |
child | Child to destroy |
void setUnparsed | ( | Type | id | ) | [inline] |
Set the last xml type that we were parsing, but we have not finished
id | The xml type that we haven't finish to parse |
void skipBlanks | ( | ) | [protected] |
Remove blank characters from the begining of the buffer
Unescape the given text. Handled: < > ' " & &#DecimalNumber; &#xHexNumber;
text | The requested text to unescape |
Type unparsed | ( | ) | [inline] |
Check if a given string is a valid xml tag name
buf | The string to check |
unsigned int m_column [protected] |
The column where the parser was stop
Error m_error [protected] |
The error code found while parsing data
unsigned int m_offset [protected] |
The offset where the parser was stop
The parser data holder. Keeps the parsed data when an incomplete xml object is found
unsigned int m_row [protected] |
The row where the parser was stop
Type m_unparsed [protected] |
The last parsed xml object code
const TokenDict s_errorString[] [static] |
Errors dictionary