libyang  1.0.184
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 {
50 
58 struct lyxml_ns {
60  struct lyxml_ns *next;
61  struct lyxml_elem *parent;
62  const char *prefix;
63  const char *value;
64 };
65 
75 struct lyxml_attr {
77  struct lyxml_attr *next;
78  const struct lyxml_ns *ns;
79  const char *name;
80  const char *value;
81 };
82 
92 struct lyxml_elem {
93  char flags;
94 #define LYXML_ELEM_MIXED 0x01 /* element contains mixed content */
95 /* 0x80 is reserved and cannot be set! */
96 
97  struct lyxml_elem *parent;
98  struct lyxml_attr *attr;
99  struct lyxml_elem *child;
100  struct lyxml_elem *next;
101  struct lyxml_elem *prev;
103  const char *name;
104  const struct lyxml_ns *ns;
105  const char *content;
106 };
107 
108 /*
109  * Functions
110  * Parser
111  */
112 
121 #define LYXML_PARSE_MULTIROOT 0x01
126 #define LYXML_PARSE_NOMIXEDCONTENT 0x02
145 struct lyxml_elem *lyxml_parse_mem(struct ly_ctx *ctx, const char *data, int options);
146 
157 struct lyxml_elem *lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options);
158 
169 #define LYXML_PRINT_OPEN 0x01
173 #define LYXML_PRINT_FORMAT 0x02
177 #define LYXML_PRINT_CLOSE 0x04
181 #define LYXML_PRINT_ATTRS 0x08
184 #define LYXML_PRINT_SIBLINGS 0x10
189 #define LYXML_PRINT_NO_LAST_NEWLINE 0x20
207 int lyxml_print_file(FILE * stream, const struct lyxml_elem *elem, int options);
208 
219 int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options);
220 
232 int lyxml_print_mem(char **strp, const struct lyxml_elem *elem, int options);
233 
245 int lyxml_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyxml_elem *elem, int options);
246 
259 struct lyxml_elem *lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root);
260 
268 void lyxml_free(struct ly_ctx *ctx, struct lyxml_elem *elem);
269 
278 void lyxml_free_withsiblings(struct ly_ctx *ctx, struct lyxml_elem *elem);
279 
288 void lyxml_unlink(struct ly_ctx *ctx, struct lyxml_elem *elem);
289 
293 const char *lyxml_get_attr(const struct lyxml_elem *elem, const char *name, const char *ns);
294 
302 const struct lyxml_ns *lyxml_get_ns(const struct lyxml_elem *elem, const char *prefix);
303 
306 #ifdef __cplusplus
307 }
308 #endif
309 
310 #endif /* LY_XML_H_ */
lyxml_ns::next
struct lyxml_ns * next
Definition: xml.h:60
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:100
lyxml_attr::next
struct lyxml_attr * next
Definition: xml.h:77
lyxml_ns::parent
struct lyxml_elem * parent
Definition: xml.h:61
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:105
lyxml_elem::flags
char flags
Definition: xml.h:93
lyxml_elem
Structure describing an element in an XML tree.
Definition: xml.h:92
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:99
lyxml_attr
Element's attribute definition.
Definition: xml.h:75
ly_ctx
libyang context handler.
LYXML_ATTR_STD
@ LYXML_ATTR_STD
Definition: xml.h:46
lyxml_ns::prefix
const char * prefix
Definition: xml.h:62
lyxml_attr::name
const char * name
Definition: xml.h:79
lyxml_elem::attr
struct lyxml_attr * attr
Definition: xml.h:98
lyxml_ns::value
const char * value
Definition: xml.h:63
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:101
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:59
lyxml_attr::ns
const struct lyxml_ns * ns
Definition: xml.h:78
lyxml_ns
Namespace definition.
Definition: xml.h:58
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.
LYXML_ATTR_STD_UNRES
@ LYXML_ATTR_STD_UNRES
Definition: xml.h:48