libyang  1.0.253
YANG data modeling language library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
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_ */
struct lyxml_ns * next
Definition: xml.h:60
struct lyxml_elem * next
Definition: xml.h:100
struct lyxml_attr * next
Definition: xml.h:77
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:93
int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
Element&#39;s attribute definition.
Definition: xml.h:75
struct lyxml_elem * parent
Definition: xml.h:61
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:105
struct lyxml_elem * child
Definition: xml.h:99
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. ...
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:62
struct lyxml_ns * ns
Definition: xml.h:78
struct lyxml_attr * attr
Definition: xml.h:98
const char * name
Definition: xml.h:79
Structure describing an element in an XML tree.
Definition: xml.h:92
const char * value
Definition: xml.h:63
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:101
struct lyxml_elem * lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options)
Parse XML from filesystem.
Namespace definition.
Definition: xml.h:58
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:59
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