libyang  1.0.101
YANG data modeling language library
xml.h
Go to the documentation of this file.
1 
15 #ifndef LY_XML_H_
16 #define LY_XML_H_
17 
18 #include <sys/types.h>
19 #include <stdio.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
33 /*
34  * Structures
35  */
36 
37 /*
38  * structure definition from context.h
39  */
40 struct ly_ctx;
41 
45 typedef enum lyxml_attr_type {
49 
57 struct lyxml_ns {
59  struct lyxml_ns *next;
60  struct lyxml_elem *parent;
61  const char *prefix;
62  const char *value;
63 };
64 
74 struct lyxml_attr {
76  struct lyxml_attr *next;
77  const struct lyxml_ns *ns;
78  const char *name;
79  const char *value;
80 };
81 
91 struct lyxml_elem {
92  char flags;
93 #define LYXML_ELEM_MIXED 0x01 /* element contains mixed content */
94 /* 0x80 is reserved and cannot be set! */
95 
96  struct lyxml_elem *parent;
97  struct lyxml_attr *attr;
98  struct lyxml_elem *child;
99  struct lyxml_elem *next;
100  struct lyxml_elem *prev;
102  const char *name;
103  const struct lyxml_ns *ns;
104  const char *content;
105 };
106 
107 /*
108  * Functions
109  * Parser
110  */
111 
120 #define LYXML_PARSE_MULTIROOT 0x01
125 #define LYXML_PARSE_NOMIXEDCONTENT 0x02
144 struct lyxml_elem *lyxml_parse_mem(struct ly_ctx *ctx, const char *data, int options);
145 
156 struct lyxml_elem *lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options);
157 
168 #define LYXML_PRINT_OPEN 0x01
172 #define LYXML_PRINT_FORMAT 0x02
176 #define LYXML_PRINT_CLOSE 0x04
180 #define LYXML_PRINT_ATTRS 0x08
183 #define LYXML_PRINT_SIBLINGS 0x10
188 #define LYXML_PRINT_NO_LAST_NEWLINE 0x20
206 int lyxml_print_file(FILE * stream, const struct lyxml_elem *elem, int options);
207 
218 int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options);
219 
231 int lyxml_print_mem(char **strp, const struct lyxml_elem *elem, int options);
232 
244 int lyxml_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyxml_elem *elem, int options);
245 
258 struct lyxml_elem *lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root);
259 
267 void lyxml_free(struct ly_ctx *ctx, struct lyxml_elem *elem);
268 
277 void lyxml_free_withsiblings(struct ly_ctx *ctx, struct lyxml_elem *elem);
278 
287 void lyxml_unlink(struct ly_ctx *ctx, struct lyxml_elem *elem);
288 
292 const char *lyxml_get_attr(const struct lyxml_elem *elem, const char *name, const char *ns);
293 
301 const struct lyxml_ns *lyxml_get_ns(const struct lyxml_elem *elem, const char *prefix);
302 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif /* LY_XML_H_ */
struct lyxml_ns * next
Definition: xml.h:59
struct lyxml_elem * next
Definition: xml.h:99
struct lyxml_attr * next
Definition: xml.h:76
int lyxml_print_mem(char **strp, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
lyxml_attr_type
enumeration of attribute types
Definition: xml.h:45
char flags
Definition: xml.h:92
int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
Element's attribute definition.
Definition: xml.h:74
struct lyxml_elem * parent
Definition: xml.h:60
void lyxml_free_withsiblings(struct ly_ctx *ctx, struct lyxml_elem *elem)
Free (and unlink from the XML tree) the specified (sub)tree with all its attributes and namespace def...
const char * content
Definition: xml.h:104
struct lyxml_elem * child
Definition: xml.h:98
void lyxml_unlink(struct ly_ctx *ctx, struct lyxml_elem *elem)
Unlink the element from its parent. In contrast to lyxml_free(), after return the caller can still ma...
const char * prefix
Definition: xml.h:61
struct lyxml_attr * attr
Definition: xml.h:97
const char * name
Definition: xml.h:78
Structure describing an element in an XML tree.
Definition: xml.h:91
const char * value
Definition: xml.h:62
int lyxml_print_clb(ssize_t(*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
struct lyxml_elem * prev
Definition: xml.h:100
const struct lyxml_ns * lyxml_get_ns(const struct lyxml_elem *elem, const char *prefix)
Get namespace definition of the given prefix in context of the specified element.
struct lyxml_elem * lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options)
Parse XML from filesystem.
const struct lyxml_ns * ns
Definition: xml.h:77
Namespace definition.
Definition: xml.h:57
const char * lyxml_get_attr(const struct lyxml_elem *elem, const char *name, const char *ns)
Get value of the attribute in the specified element.
struct lyxml_elem * lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root)
Duplicate the XML tree into the different content.
LYXML_ATTR_TYPE type
Definition: xml.h:58
libyang context handler.
void lyxml_free(struct ly_ctx *ctx, struct lyxml_elem *elem)
Free (and unlink from the XML tree) the specified element with all its attributes and namespace defin...
enum lyxml_attr_type LYXML_ATTR_TYPE
enumeration of attribute types