libyang  1.0.130
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_ */
lyxml_ns::next
struct lyxml_ns * next
Definition: xml.h:59
lyxml_attr_type
lyxml_attr_type
enumeration of attribute types
Definition: xml.h:45
lyxml_unlink
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...
lyxml_print_mem
int lyxml_print_mem(char **strp, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
lyxml_elem::next
struct lyxml_elem * next
Definition: xml.h:99
lyxml_attr::next
struct lyxml_attr * next
Definition: xml.h:76
lyxml_ns::parent
struct lyxml_elem * parent
Definition: xml.h:60
lyxml_print_fd
int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
lyxml_elem::content
const char * content
Definition: xml.h:104
lyxml_elem::flags
char flags
Definition: xml.h:92
lyxml_elem
Structure describing an element in an XML tree.
Definition: xml.h:91
lyxml_free_withsiblings
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...
lyxml_elem::child
struct lyxml_elem * child
Definition: xml.h:98
lyxml_attr
Element's attribute definition.
Definition: xml.h:74
ly_ctx
libyang context handler.
LYXML_ATTR_STD
@ LYXML_ATTR_STD
Definition: xml.h:46
lyxml_ns::prefix
const char * prefix
Definition: xml.h:61
lyxml_attr::name
const char * name
Definition: xml.h:78
lyxml_elem::attr
struct lyxml_attr * attr
Definition: xml.h:97
lyxml_ns::value
const char * value
Definition: xml.h:62
lyxml_print_clb
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.
lyxml_elem::prev
struct lyxml_elem * prev
Definition: xml.h:100
LYXML_ATTR_NS
@ LYXML_ATTR_NS
Definition: xml.h:47
lyxml_dup
struct lyxml_elem * lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root)
Duplicate the XML tree into the different content.
LYXML_ATTR_TYPE
enum lyxml_attr_type LYXML_ATTR_TYPE
enumeration of attribute types
lyxml_get_attr
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.
lyxml_ns::type
LYXML_ATTR_TYPE type
Definition: xml.h:58
lyxml_attr::ns
const struct lyxml_ns * ns
Definition: xml.h:77
lyxml_ns
Namespace definition.
Definition: xml.h:57
lyxml_parse_path
struct lyxml_elem * lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options)
Parse XML from filesystem.
lyxml_free
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...
lyxml_get_ns
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.