APG
… an ABNF Parser Generator
|
The APG XML parser. More...
Go to the source code of this file.
Data Structures | |
struct | input_info |
Information about the input data. More... | |
Macros | |
Misc. Constants | |
Some misc. constants used by the parser. | |
#define | TAB 9 |
#define | LF 10 |
#define | CR 13 |
#define | LINE_LEN 16 |
#define | LINE_LEN4 4 |
#define | LINE_LEN8 8 |
#define | LINE_LEN12 12 |
#define | LT 0x3C |
#define | CHARS_LINE_LEN 8 |
#define | CHAR_BUF_LEN 256 |
Functions | |
void * | vpXmlCtor (exception *spEx) |
The XML Parser constructor. More... | |
void | vXmlDtor (void *vpCtx) |
The XML Parser component destructor. More... | |
abool | bXmlValidate (void *vpCtx) |
Validate an XML context pointer. More... | |
void | vXmlGetFile (void *vpCtx, const char *cpFileName) |
Gets the XML byte stream from a file. More... | |
void | vXmlGetArray (void *vpCtx, uint8_t *ucpData, aint uiDataLen) |
Gets the XML byte stream from a byte array. More... | |
void | vXmlParse (void *vpCtx) |
Parse the XML data from vXmlGetFile or vXmlGetArray. More... | |
void | vXmlDisplayMsgs (void *vpCtx) |
Display the parser's messages on stdout, if any. More... | |
void * | vpXmlGetMsgs (void *vpCtx) |
Give the user a handle to the message log. More... | |
void | vXmlSetStartTagCallback (void *vpCtx, pfnStartTagCallback pfnCallback, void *vpUserData) |
Set the user's callback function for the start tags (<name attr="10"> ). More... | |
void | vXmlSetEmptyTagCallback (void *vpCtx, pfnEmptyTagCallback pfnCallback, void *vpUserData) |
Set the user's callback function for the empty tags (<name attr="10"/> ). More... | |
void | vXmlSetEndTagCallback (void *vpCtx, pfnEndTagCallback pfnCallback, void *vpUserData) |
Set the user's callback function for the end tags (</name> ). More... | |
void | vXmlSetPICallback (void *vpCtx, pfnPICallback pfnCallback, void *vpUserData) |
Set the user's callback function for the Processing Instruction tags(<?target instructions?> ). More... | |
void | vXmlSetXmlDeclCallback (void *vpCtx, pfnXmlDeclCallback pfnCallback, void *vpUserData) |
Set the user's callback function for the XML declaration. More... | |
void | vXmlSetDTDCallback (void *vpCtx, pfnDTDCallback pfnCallback, void *vpUserData) |
Set the user's callback function for the Processing Instruction tags(<?target instructions?> ). More... | |
void | vXmlSetCommentCallback (void *vpCtx, pfnCommentCallback pfnCallback, void *vpUserData) |
Set the user's callback function for comments. More... | |
void | vXmlDisplayInput (void *vpCtx, abool bShowLines) |
Display input file. More... | |
The APG XML parser.
This is meant to be a standards-compliant, non-validating XML parser. XML input may be UTF-8, UTF-16BE or UTF-16LE. If UTF-16, a Byte Order Mark (BOM) must be present and UTF-16 must be specified in the XML declaration which must be present. UTF-16 format is transcoded to UTF-8 prior to parsing. All line ends are converted to 0x0A (\n or LF) and all characters are checked for XML character validity.
The Document Type Declaration (DTD) internal subset, if present, is parsed and entity declarations and default attribute values are tabulated and used when parsing the document body.
All applicable well-formedness constraints are checked.
Definition in file xml.c.
abool bXmlValidate | ( | void * | vpCtx | ) |
void* vpXmlCtor | ( | exception * | spEx | ) |
The XML Parser constructor.
Allocates memory for the XML Parser component and constructs all of the required working memory vectors. All display is to stdout
and the default values of all callback function pointers are NULL. To set the callback functions see:
vXmlSetXmlDeclCallback
vXmlSetDTDCallback
vXmlSetEmptyTagCallback
vXmlSetStartTagCallback
vXmlSetEndTagCallback
vXmlSetPICallback
vXmlSetCommentCallback
Note that this parser assumes that input is always in the form of 8-bit byte streams and that the type "char" is also 8-bits. For string functions, it is always assumed that conversions from uint8_t to char is OK.
spEx | Pointer to a valid exception structure. |
void* vpXmlGetMsgs | ( | void * | vpCtx | ) |
void vXmlDisplayInput | ( | void * | vpCtx, |
abool | bShowLines | ||
) |
Display input file.
This utility function will display the (converted*) input byte stream in hexdump format, displaying the data as both hex bytes and ASCII for printing characters.
*
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | bShowLines | - if true (!= 0) data is displayed by line number. Otherwise, just a dump blob. |
void vXmlDisplayMsgs | ( | void * | vpCtx | ) |
Display the parser's messages on stdout, if any.
Nothing is displayed if there are no messages. Messages are collected as the parser detects errors in the DTD. Other than the DTD, fatal errors result in a thrown exception.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
void vXmlDtor | ( | void * | vpCtx | ) |
The XML Parser component destructor.
Releases all heap memory and clears the context to prevent accidental use after release.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
void vXmlGetArray | ( | void * | vpCtx, |
uint8_t * | ucpData, | ||
aint | uiDataLen | ||
) |
Gets the XML byte stream from a byte array.
The first four characters are examined to determine the encoding scheme. The data is the normalized as follows:
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | ucpData | - The input byte stream as an array of unsigned characters. |
[in] | uiDataLen | - The number of bytes in the stream. |
void vXmlGetFile | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
Gets the XML byte stream from a file.
This function just serves to get the file into a memory array. vXmlGetArray is then called to do the actual work.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | cpFileName | - The name of the XML file. |
void vXmlParse | ( | void * | vpCtx | ) |
Parse the XML data from vXmlGetFile or vXmlGetArray.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
void vXmlSetCommentCallback | ( | void * | vpCtx, |
pfnCommentCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for comments.
This function is called when a comment has been found. See pfnCommentCallback for the declaration.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetDTDCallback | ( | void * | vpCtx, |
pfnDTDCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the Processing Instruction tags(<?target instructions?>
).
This function is called when a Processing Instruction tag has been found. See pfnDTDCallback for the declaration.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetEmptyTagCallback | ( | void * | vpCtx, |
pfnEmptyTagCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the empty tags (<name attr="10"/>
).
This function is called when an empty tag has been found. See pfnEmptyTagCallback for the declaration.
Note that this function presents the callback function with exactly the same information that a start tag callback will get. The user may assign the same callback function to both. The option to have separate callback functions for empty and start tags is simply a convenience in case a distinction needs to be made.
Note that the utility function vStartTagDisplay will make a simple display of the empty tag name and attributes.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetEndTagCallback | ( | void * | vpCtx, |
pfnEndTagCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the end tags (</name>
).
This function is called when an end tag has been found. See pfnEndTagCallback for the declaration.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetPICallback | ( | void * | vpCtx, |
pfnPICallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the Processing Instruction tags(<?target instructions?>
).
This function is called when a Processing Instruction tag has been found. See pfnPICallback for the declaration.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetStartTagCallback | ( | void * | vpCtx, |
pfnStartTagCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the start tags (<name attr="10">
).
This function is called when a start tag has been found. See pfnStartTagCallback for the declaration.
Note that the utility function vStartTagDisplay will make a simple display of the start tag name and attributes.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |
void vXmlSetXmlDeclCallback | ( | void * | vpCtx, |
pfnXmlDeclCallback | pfnCallback, | ||
void * | vpUserData | ||
) |
Set the user's callback function for the XML declaration.
This function is called when parsing the XML declaration has finished. See pfnXmlDeclCallback for the declaration.
[in] | vpCtx | pointer to the parser's context - previously returned from vpXmlCtor. |
[in] | pfnCallback | Pointer to the callback function to use. Use DEFAULT_CALLBACK to invoke a pre-defined callback function which will simply display the data to stdout . In this case, the vpUserData argument is ignored and my be NULL. |
[in] | vpUserData | This pointer will be passed through to the user's callback function. It is never dereferenced by the XML parser and may be NULL. |