libgpac
Documentation of the core library of GPAC
SAX Parsing
+ Collaboration diagram for SAX Parsing:

Typedefs

typedef struct _tag_sax_parser GF_SAXParser
 
typedef void(* gf_xml_sax_node_start) (void *sax_cbck, const char *node_name, const char *name_space, const GF_XMLAttribute *attributes, u32 nb_attributes)
 
typedef void(* gf_xml_sax_node_end) (void *sax_cbck, const char *node_name, const char *name_space)
 
typedef void(* gf_xml_sax_text_content) (void *sax_cbck, const char *content, Bool is_cdata)
 
typedef void(* gf_xml_sax_progress) (void *cbck, u64 done, u64 total)
 

Functions

GF_SAXParsergf_xml_sax_new (gf_xml_sax_node_start on_node_start, gf_xml_sax_node_end on_node_end, gf_xml_sax_text_content on_text_content, void *cbck)
 
void gf_xml_sax_del (GF_SAXParser *parser)
 
GF_Err gf_xml_sax_init (GF_SAXParser *parser, unsigned char *BOM)
 
GF_Err gf_xml_sax_parse (GF_SAXParser *parser, const void *string_bytes)
 
GF_Err gf_xml_sax_suspend (GF_SAXParser *parser, Bool do_suspend)
 
GF_Err gf_xml_sax_parse_file (GF_SAXParser *parser, const char *fileName, gf_xml_sax_progress OnProgress)
 
u32 gf_xml_sax_get_line (GF_SAXParser *parser)
 
char * gf_xml_sax_peek_node (GF_SAXParser *parser, char *att_name, char *att_value, char *substitute, char *get_attr, char *end_pattern, Bool *is_substitute)
 
Bool gf_xml_sax_binary_file (GF_SAXParser *parser)
 
const char * gf_xml_sax_get_error (GF_SAXParser *parser)
 
char * gf_xml_get_root_type (const char *file, GF_Err *ret_code)
 
u32 gf_xml_sax_get_node_start_pos (GF_SAXParser *parser)
 
u32 gf_xml_sax_get_node_end_pos (GF_SAXParser *parser)
 

Detailed Description

    ! SAX XML Parser API
    GPAC can do progressive loading of XML document using this SAX api.

Typedef Documentation

◆ GF_SAXParser

typedef struct _tag_sax_parser GF_SAXParser

SAX XML Parser object

◆ gf_xml_sax_node_start

typedef void(* gf_xml_sax_node_start) (void *sax_cbck, const char *node_name, const char *name_space, const GF_XMLAttribute *attributes, u32 nb_attributes)

SAX XML node start callback

Parameters
sax_cbckuser data passed durinc creation of SAX parser
node_namename of the XML node starting
name_spacenamespace of the XML node starting
attributesarray of attributes declared for that XML node
nb_attributesnumber of items in array

◆ gf_xml_sax_node_end

typedef void(* gf_xml_sax_node_end) (void *sax_cbck, const char *node_name, const char *name_space)

SAX XML node end callback

Parameters
sax_cbckuser data passed durinc creation of SAX parser
node_namename of the XML node starting
name_spacenamespace of the XML node starting

◆ gf_xml_sax_text_content

typedef void(* gf_xml_sax_text_content) (void *sax_cbck, const char *content, Bool is_cdata)

SAX text content callback

Parameters
sax_cbckuser data passed durinc creation of SAX parser
contenttext content of the node
is_cdataif TRUE the content was ancapsulated in CDATA; otherwise this isthe content of a text node

◆ gf_xml_sax_progress

typedef void(* gf_xml_sax_progress) (void *cbck, u64 done, u64 total)

SAX progress callback

Parameters
cbckuser data passed durinc creation of SAX parser
doneamount of bytes parsed from the file
totaltotal number of bytes in the file

Function Documentation

◆ gf_xml_sax_new()

GF_SAXParser* gf_xml_sax_new ( gf_xml_sax_node_start  on_node_start,
gf_xml_sax_node_end  on_node_end,
gf_xml_sax_text_content  on_text_content,
void *  cbck 
)

creates new sax parser - all callbacks are optionals

Parameters
on_node_startcallback for XML node start
on_node_endcallback for XML node end
on_text_contentcallback for text content
cbckuser data passed to callback functions
Returns
a SAX parser object

◆ gf_xml_sax_del()

void gf_xml_sax_del ( GF_SAXParser parser)

destroys sax parser

Parameters
parserthe SAX parser to destroy

◆ gf_xml_sax_init()

GF_Err gf_xml_sax_init ( GF_SAXParser parser,
unsigned char *  BOM 
)

Inits the parser with string containing BOM, if any. BOM must be 4 char string with 0 terminaison. If BOM is NULL, parsing will assume UTF-8 compatible coding

Parameters
parserthe SAX parser to init
BOMthe 4 character with 0 terminaison BOM or NULL
Returns
error code if any

◆ gf_xml_sax_parse()

GF_Err gf_xml_sax_parse ( GF_SAXParser parser,
const void *  string_bytes 
)

Parses input string data. string data MUST be terminated by the 0 character (eg 2 0s for UTF-16)

Parameters
parserthe SAX parser to use
string_bytesthe string to parse
Returns
error code if any

◆ gf_xml_sax_suspend()

GF_Err gf_xml_sax_suspend ( GF_SAXParser parser,
Bool  do_suspend 
)

Suspends or resumes SAX parsing. When resuming on file, the function will run until suspended/end of file/error When resuming on steram, the function will simply return

Parameters
parserthe SAX parser to use
do_suspendif GF_TRUE, SAX parsing is suspended, otherwise SAX parsing is resumed
Returns
error code if any

◆ gf_xml_sax_parse_file()

GF_Err gf_xml_sax_parse_file ( GF_SAXParser parser,
const char *  fileName,
gf_xml_sax_progress  OnProgress 
)

parses file (potentially gzipped). OnProgress is optional, used to get progress callback

Parameters
parserthe SAX parser to use
fileNamethe file to parse
OnProgressthe progress function to use. The callback for the progress function is the one assigned at SAX parser creation gf_xml_sax_new
Returns
error code if any

◆ gf_xml_sax_get_line()

u32 gf_xml_sax_get_line ( GF_SAXParser parser)

Gets current line number, useful for inspecting errors

Parameters
parserthe SAX parser to use
Returns
current line number of SAX parser

◆ gf_xml_sax_peek_node()

char* gf_xml_sax_peek_node ( GF_SAXParser parser,
char *  att_name,
char *  att_value,
char *  substitute,
char *  get_attr,
char *  end_pattern,
Bool is_substitute 
)

Peeks a node forward in the file. This may be used to pick the attribute of the first node found matching a given (attributeName, attributeValue) couple

Parameters
parserSAX parser to use
att_nameattribute name to look for
att_valuevalue for this attribute
substitutegives the name of an additional XML node type to inspect to match the node. May be NULL.
get_attrgives the name of the attribute in the substitute node that matches the condition. If substitue node with name atribute is found, the content of the name attribute is returned. May be NULL.
end_patterngives a string indicating where to stop looking in the document. May be NULL.
is_substituteis set to GF_TRUE if the return value corresponds to the content of the name attribute of the substitute element
Returns
name of the XML node found, or NULL if no match. This string has to be freed by the caller using gf_free

◆ gf_xml_sax_binary_file()

Bool gf_xml_sax_binary_file ( GF_SAXParser parser)

For file mode only, indicates if a file is compressed or not

Parameters
parserSAX parser to use
Returns
1 if file is compressed, 0 otherwise

◆ gf_xml_sax_get_error()

const char* gf_xml_sax_get_error ( GF_SAXParser parser)

Returns the last error found during parsing

Parameters
parserSAX parser
Returns
the last SAX error encountered

◆ gf_xml_get_root_type()

char* gf_xml_get_root_type ( const char *  file,
GF_Err ret_code 
)

Returns the name of the root XML element

Parameters
filethe XML file to inspect
ret_codereturn error code if any
Returns
the name of the root XML element. This string has to be freed by the caller using gf_free

◆ gf_xml_sax_get_node_start_pos()

u32 gf_xml_sax_get_node_start_pos ( GF_SAXParser parser)

Returns the position in bytes of the start of the current node being parsed. The byte offset points to the first < character in the opening tag.

Parameters
parserSAX parser
Returns
the 0-based position of the current XML node

◆ gf_xml_sax_get_node_end_pos()

u32 gf_xml_sax_get_node_end_pos ( GF_SAXParser parser)

Returns the position in bytes of the end of the current node being parsed. The byte offset points to the last > character in the closing tag.

Parameters
parserSAX parser
Returns
the 0-based position of the current XML node