~ubuntu-branches/debian/lenny/libgsf/lenny

« back to all changes in this revision

Viewing changes to gsf/gsf-libxml.h

  • Committer: Bazaar Package Importer
  • Author(s): J.H.M. Dassen (Ray)
  • Date: 2006-11-06 22:45:03 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20061106224503-g6pmv1m82zy8jya9
Tags: 1.14.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * gsf-libxml.h: Utility wrappers for using gsf with libxml
4
4
 *
5
 
 * Copyright (C) 2002-2004 Jody Goldberg (jody@gnome.org)
 
5
 * Copyright (C) 2002-2005 Jody Goldberg (jody@gnome.org)
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or
8
8
 * modify it under the terms of version 2.1 of the GNU Lesser General Public
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public License
17
17
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19
19
 * USA
20
20
 */
21
21
 
41
41
                                       gboolean    format);
42
42
 
43
43
/****************************************************************************/
44
 
/* Simplified GSF based xml import (based on libxml2 SAX) */
45
 
typedef struct _GsfXMLBlob      GsfXMLBlob;
46
 
 
47
 
typedef struct _GsfXMLIn        GsfXMLIn;
48
 
typedef struct _GsfXMLInDoc     GsfXMLInDoc;
49
 
typedef struct _GsfXMLInNode    GsfXMLInNode;
50
 
typedef struct _GsfXMLInNS      GsfXMLInNS;
51
 
 
 
44
/* Simplified wrapper to SAX based xml import */
 
45
typedef struct _GsfXMLIn                GsfXMLIn;
 
46
typedef struct _GsfXMLInDoc             GsfXMLInDoc;
 
47
typedef struct _GsfXMLInNode            GsfXMLInNode;
 
48
typedef struct _GsfXMLInNS              GsfXMLInNS;
 
49
typedef struct _GsfXMLBlob              GsfXMLBlob;
52
50
typedef enum {
53
 
        GSF_XML_NO_CONTENT,
 
51
        GSF_XML_NO_CONTENT = FALSE,
54
52
        GSF_XML_CONTENT,
55
53
        GSF_XML_SHARED_CONTENT
56
54
} GsfXMLContent;
 
55
typedef gboolean (*GsfXMLInUnknownFunc) (GsfXMLIn *xin,
 
56
                                         xmlChar const *elem, xmlChar const **attrs);
 
57
typedef void     (*GsfXMLInExtDtor)     (GsfXMLIn *xin, gpointer old_state);
57
58
 
58
59
struct _GsfXMLIn {
59
 
        GsfXMLInDoc  const *doc;        /* init before parsing */
60
 
 
61
 
    /* look but do not change */
62
 
        GsfXMLInNode const *node;       /* current node */
63
 
        GSList             *state_stack;
64
 
 
65
 
        GsfXMLInNS   const *default_ns; /* optionally NULL */
66
 
        GSList             *ns_stack;
67
 
 
68
 
        GString         *content;
69
 
        gint             unknown_depth; /* handle recursive unknown tags */
70
 
        GHashTable      *ns_prefixes;   /* current ns prefixes */
71
 
        GPtrArray       *ns_by_id;              /* indexed by id */
 
60
        /* public state : read only */
 
61
        gpointer            user_state;
 
62
        GString            *content;
 
63
        GsfXMLInDoc  const *doc;
 
64
        GsfXMLInNode const *node;       /* current node (not on the stack) */
 
65
        GSList             *node_stack; /* stack of GsfXMLInNode */
72
66
};
73
67
 
74
68
struct _GsfXMLInNode {
75
 
        char const *id;
 
69
        char const *id;         /* unique in the entire tree */
76
70
        int         ns_id;
77
71
        char const *name;
78
72
        char const *parent_id;
79
 
        gboolean parent_initialized;
80
 
        GSList *groups;
81
 
 
82
 
        unsigned        has_content;
83
 
        gboolean        allow_unknown;
84
 
        gboolean        check_children_for_ns;
85
 
 
86
 
        void (*start) (GsfXMLIn *state, xmlChar const **attrs);
87
 
        void (*end)   (GsfXMLIn *state, GsfXMLBlob *unknown);
 
73
        void (*start) (GsfXMLIn *xin, xmlChar const **attrs);
 
74
        void (*end)   (GsfXMLIn *xin, GsfXMLBlob *unknown);
88
75
 
89
76
        union {
90
77
                int         v_int;
92
79
                gpointer    v_blob;
93
80
                char const *v_str;
94
81
        } user_data;
 
82
        GsfXMLContent has_content;
 
83
 
 
84
        unsigned int check_children_for_ns : 1;
 
85
        unsigned int share_children_with_parent : 1;
95
86
};
96
87
 
97
88
struct _GsfXMLInNS {
100
91
};
101
92
 
102
93
#define GSF_XML_IN_NS(id, uri) \
103
 
{ uri, id}
 
94
{ uri, id }
104
95
 
105
96
#define GSF_XML_IN_NODE_FULL(parent_id, id, ns, name, has_content,      \
106
 
                             allow_unknown, check_ns, start, end, user) \
 
97
                             share_children_with_parent, check_ns, start, end, user)    \
107
98
{                                                                       \
108
 
        #id, ns, name, #parent_id, FALSE, NULL,                         \
109
 
        has_content, allow_unknown, check_ns, start, end, { user }      \
 
99
        #id, ns, name, #parent_id, start, end, { user }, has_content,   \
 
100
        check_ns, share_children_with_parent,                           \
110
101
}
111
102
 
112
103
#define GSF_XML_IN_NODE(parent_id, id, ns, name, has_content, start, end) \
113
104
        GSF_XML_IN_NODE_FULL(parent_id, id, ns, name, has_content,        \
114
105
                             FALSE, FALSE, start, end, 0)
115
 
 
116
 
GsfXMLInDoc *gsf_xml_in_doc_new  (GsfXMLInNode *root, GsfXMLInNS *ns);
117
 
void         gsf_xml_in_doc_free (GsfXMLInDoc *doc);
118
 
 
119
 
gboolean    gsf_xml_in_parse     (GsfXMLIn *state, GsfInput *input);
120
 
char const *gsf_xml_in_check_ns  (GsfXMLIn const *state, char const *str,
121
 
                                  unsigned int ns_id);
122
 
gboolean    gsf_xml_in_namecmp   (GsfXMLIn const *state, char const *str,
123
 
                                  unsigned int ns_id, char const *name);
 
106
#define GSF_XML_IN_NODE_END     \
 
107
        { NULL, 0, NULL, NULL, NULL, NULL, { 0 }, GSF_XML_NO_CONTENT, FALSE, FALSE }
 
108
 
 
109
GsfXMLInDoc *gsf_xml_in_doc_new    (GsfXMLInNode const *nodes, GsfXMLInNS const *ns);
 
110
void         gsf_xml_in_doc_free   (GsfXMLInDoc *doc);
 
111
gboolean     gsf_xml_in_doc_parse  (GsfXMLInDoc *doc, GsfInput *input,
 
112
                                    gpointer user_state);
 
113
void         gsf_xml_in_doc_set_unknown_handler (GsfXMLInDoc *doc,
 
114
                                    GsfXMLInUnknownFunc handler);
 
115
 
 
116
void         gsf_xml_in_push_state (GsfXMLIn *xin, GsfXMLInDoc const *doc,
 
117
                                    gpointer new_state, GsfXMLInExtDtor dtor,
 
118
                                    xmlChar const **attrs);
 
119
 
 
120
GsfInput    *gsf_xml_in_get_input  (GsfXMLIn const *xin);
 
121
char const  *gsf_xml_in_check_ns   (GsfXMLIn const *xin, char const *str,
 
122
                                    unsigned int ns_id);
 
123
gboolean     gsf_xml_in_namecmp    (GsfXMLIn const *xin, char const *str,
 
124
                                    unsigned int ns_id, char const *name);
124
125
 
125
126
/****************************************************************************/
126
127
/* Simplified GSF based xml export (does not use libxml) */
136
137
 
137
138
void        gsf_xml_out_set_doc_type    (GsfXMLOut *xml, char const *type);
138
139
void        gsf_xml_out_start_element   (GsfXMLOut *xml, char const *id);
139
 
const char *gsf_xml_out_end_element     (GsfXMLOut *xml);
 
140
char const *gsf_xml_out_end_element     (GsfXMLOut *xml);
140
141
 
141
142
void gsf_xml_out_simple_element         (GsfXMLOut *xml, char const *id,
142
143
                                         char const *content);
161
162
                                         unsigned int r, unsigned int g, unsigned int b);
162
163
void gsf_xml_out_add_base64             (GsfXMLOut *xml, char const *id,
163
164
                                         guint8 const *data, unsigned int len);
 
165
void gsf_xml_out_add_enum               (GsfXMLOut *xml, char const *id,
 
166
                                         GType etype, gint val);
 
167
void gsf_xml_out_add_gvalue             (GsfXMLOut *xml, char const *id,
 
168
                                         GValue const *val);
164
169
 
165
 
/* TODO : something for enums ? */
 
170
/****************************************************************************/
 
171
/* Some general utilities */
 
172
gboolean gsf_xml_gvalue_from_str (GValue *res, GType t, char const *str);
166
173
 
167
174
G_END_DECLS
168
175