2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / common tools sub-project
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
25 #ifndef _XML_PARSER_H_
\r
26 #define _XML_PARSER_H_
\r
32 #include <gpac/tools.h>
\r
33 #include <gpac/list.h>
\r
36 * \file <gpac/xml.h>
\r
37 * \brief XML functions.
\r
41 * \addtogroup xml_grp XML
\r
42 * \ingroup utils_grp
\r
43 * \brief XML Parsing functions
\r
45 *This section documents the XML functions of the GPAC framework.\n
\r
53 /*name or namespace:name*/
\r
62 GF_XML_NODE_TYPE = 0,
\r
67 typedef struct _xml_node
\r
72 For other (text, css, cdata), element content
\r
76 /*for DOM nodes only*/
\r
77 char *ns; /*namespace*/
\r
78 GF_List *attributes;
\r
88 typedef struct _tag_sax_parser GF_SAXParser;
\r
89 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);
\r
90 typedef void (*gf_xml_sax_node_end)(void *sax_cbck, const char *node_name, const char *name_space);
\r
91 typedef void (*gf_xml_sax_text_content)(void *sax_cbck, const char *content, Bool is_cdata);
\r
93 typedef void (*gf_xml_sax_progress)(void *cbck, u32 done, u32 tot);
\r
95 /*creates new sax parser - all callbacks are optionals*/
\r
96 GF_SAXParser *gf_xml_sax_new(gf_xml_sax_node_start on_node_start,
\r
97 gf_xml_sax_node_end on_node_end,
\r
98 gf_xml_sax_text_content on_text_content,
\r
101 /*destroys sax parser */
\r
102 void gf_xml_sax_del(GF_SAXParser *parser);
\r
103 /*inits parser with BOM. BOM must be 4 char string with 0 terminaison. If BOM is NULL, parsing will
\r
104 assume UTF-8 compatible coding*/
\r
105 GF_Err gf_xml_sax_init(GF_SAXParser *parser, unsigned char *BOM);
\r
106 /*parses input string data. string data MUST be terminated by the 0 character (eg 2 0s for UTF-16)*/
\r
107 GF_Err gf_xml_sax_parse(GF_SAXParser *parser, void *string_bytes);
\r
108 /*suspends/resume sax parsing.
\r
109 When resuming on file, the function will run until suspended/end of file/error
\r
110 When resuming on steram, the function will simply return
\r
112 GF_Err gf_xml_sax_suspend(GF_SAXParser *parser, Bool do_suspend);
\r
113 /*parses file (potentially gzipped). OnProgress is optional, used to get progress callback*/
\r
114 GF_Err gf_xml_sax_parse_file(GF_SAXParser *parser, const char *fileName, gf_xml_sax_progress OnProgress);
\r
115 /*get current line number*/
\r
116 u32 gf_xml_sax_get_line(GF_SAXParser *parser);
\r
117 /*get file size - may be inaccurate if gzipped (only compressed file size is known)*/
\r
118 u32 gf_xml_sax_get_file_size(GF_SAXParser *parser);
\r
119 /*get current file position*/
\r
120 u32 gf_xml_sax_get_file_pos(GF_SAXParser *parser);
\r
122 /*peeks a node forward in the file. May be used to pick the attribute of the first node found matching a given (attributeName, attributeValue) couple*/
\r
123 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);
\r
125 /*file mode only, returns 1 if file is compressed, 0 otherwise*/
\r
126 Bool gf_xml_sax_binary_file(GF_SAXParser *parser);
\r
128 const char *gf_xml_sax_get_error(GF_SAXParser *parser);
\r
130 char *gf_xml_get_root_type(const char *file, GF_Err *ret_code);
\r
132 u32 gf_xml_sax_get_node_start_pos(GF_SAXParser *parser);
\r
133 u32 gf_xml_sax_get_node_end_pos(GF_SAXParser *parser);
\r
136 typedef struct _tag_dom_parser GF_DOMParser;
\r
137 GF_DOMParser *gf_xml_dom_new();
\r
138 void gf_xml_dom_del(GF_DOMParser *parser);
\r
139 GF_Err gf_xml_dom_parse(GF_DOMParser *parser, const char *file, gf_xml_sax_progress OnProgress, void *cbk);
\r
140 GF_XMLNode *gf_xml_dom_get_root(GF_DOMParser *parser);
\r
141 const char *gf_xml_dom_get_error(GF_DOMParser *parser);
\r
142 u32 gf_xml_dom_get_line(GF_DOMParser *parser);
\r
144 char *gf_xml_dom_serialize(GF_XMLNode *node, Bool content_only);
\r
147 GF_XMLNode *gf_xml_dom_detach_root(GF_DOMParser *parser);
\r
148 void gf_xml_dom_node_del(GF_XMLNode *node);
\r
157 #endif /*_XML_PARSER_H_*/
\r