summaryrefslogtreecommitdiff
path: root/src/xml.h
blob: 82e257860d835b7972a2d48b0a537a821877e951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

/* Firebox Tools - Outils de configurations pour le WM Firebox
 * xml.h - prototypes pour la lecture ou l'écriture de documents XML
 *
 * Copyright (C) 2006-2007 Cyrille Bagard
 *
 *  This file is part of Firebox Tools.
 *
 *  Firebox Tools is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Firebox Tools is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef _XML_H
#define _XML_H


#include <stdbool.h>
#include <glib/gtypes.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#include <libxml/xpath.h>




/* Crée un nouveau fichier XML. */
bool create_new_xml_file(xmlDocPtr *, xmlXPathContextPtr *);

/* Sauvegarde une structure XML dans un fichier. */
bool save_xml_file(xmlDocPtr, const char *);

/* Ferme une structure XML. */
void close_xml_file(xmlDocPtr, xmlXPathContextPtr);



/* --------------------- OPERATIONS DE LECTURE D'UN FICHIER XML --------------------- */


#define XPATH_OBJ_NODES_COUNT(obj) (obj != NULL ? obj->nodesetval->nodeNr : 0)
#define NODE_FROM_PATH_OBJ(obj, i) obj->nodesetval->nodeTab[i]


/* Ouvre un fichier XML de façon encadrée. */
gboolean open_xml_file(const char *filename, xmlDoc **, xmlXPathContextPtr *);

/* Obtient de façon encadrée l'accès à un noeud défini. */
xmlXPathObjectPtr get_node_xpath_object(xmlXPathContextPtr, const char *);

/* Obtient une valeur placée entre <...> et </...>. */
char *qck_get_node_text_value(xmlNodePtr);

/* Obtient une valeur placée entre <...> et </...>. */
char *get_node_text_value(xmlXPathContextPtr, const char *);

/* Obtient la valeur d'une propriété d'un élément. */
char *qck_get_node_prop_value(xmlNodePtr, const char *);

/* Obtient la valeur d'une propriété d'un élément. */
char *get_node_prop_value(xmlXPathContextPtr, const char *, const char *);

/* Construit un chemin d'accès complet selon le fichier XML. */
char *qck_build_filename_with_doc_url(xmlNodePtr);

/* Construit un chemin d'accès complet selon le fichier XML. */
char *build_filename_with_doc_url(xmlXPathContextPtr xpathCtx, const char *path);



/* --------------------- OPERATIONS D'ECRITURE D'UN FICHIER XML --------------------- */


/* Amorce l'écriture d'un nouveau fichier XML. */
xmlTextWriterPtr start_writing_xml_file(const char *);

/* Met fin à l'écriture d'un nouveau fichier XML. */
bool end_writing_xml_file(xmlTextWriterPtr);

/* Ecrit une balise et ne la referme pas. */
bool open_xml_element(xmlTextWriterPtr, const char *);

/* Ferme la dernière balise laissée ouverte. */
bool close_xml_element(xmlTextWriterPtr);

/* Ecrit une balise avec un contenu textuel. */
bool write_xml_element_with_content(xmlTextWriterPtr, const char *, const char *, ...);

/* Ecrit un attribut avec un contenu textuel. */
bool write_xml_attribute(xmlTextWriterPtr, const char *, const char *, ...);

/* Ecrit un contenu textuel. */
bool write_xml_content(xmlTextWriterPtr, const char *, ...);



/* --------------------- OPERATIONS D'ECRITURE D'UN FICHIER XML --------------------- */


/* Fournit le premier noeud correspondant à un chemin XPath. */
xmlNodePtr get_node_from_xpath(xmlXPathContextPtr, const char *);

/* S'assure qu'un noeud donné est bien présent dans le document. */
xmlNodePtr ensure_node_exist(xmlDocPtr, xmlXPathContextPtr, const char *);

/* S'assure qu'un noeud donné est bien présent dans le document. */
bool add_content_to_node(xmlDocPtr, xmlXPathContextPtr, const char *, const char *);



#endif  /* _XML_H */