libyang 1.0.184
YANG data modeling language library
Loading...
Searching...
No Matches
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
22extern "C" {
23#endif
24
33/*
34 * Structures
35 */
36
37/*
38 * structure definition from context.h
39 */
40struct ly_ctx;
41
45typedef enum lyxml_attr_type {
50
58struct lyxml_ns {
60 struct lyxml_ns *next;
62 const char *prefix;
63 const char *value;
64};
65
75struct lyxml_attr {
77 struct lyxml_attr *next;
78 const struct lyxml_ns *ns;
79 const char *name;
80 const char *value;
81};
82
92struct lyxml_elem {
93 char flags;
94#define LYXML_ELEM_MIXED 0x01 /* element contains mixed content */
95/* 0x80 is reserved and cannot be set! */
96
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
145struct lyxml_elem *lyxml_parse_mem(struct ly_ctx *ctx, const char *data, int options);
146
157struct 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
207int lyxml_print_file(FILE * stream, const struct lyxml_elem *elem, int options);
208
219int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options);
220
232int lyxml_print_mem(char **strp, const struct lyxml_elem *elem, int options);
233
245int lyxml_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyxml_elem *elem, int options);
246
259struct lyxml_elem *lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root);
260
268void lyxml_free(struct ly_ctx *ctx, struct lyxml_elem *elem);
269
278void lyxml_free_withsiblings(struct ly_ctx *ctx, struct lyxml_elem *elem);
279
288void lyxml_unlink(struct ly_ctx *ctx, struct lyxml_elem *elem);
289
293const char *lyxml_get_attr(const struct lyxml_elem *elem, const char *name, const char *ns);
294
302const 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_ */
libyang context handler.
struct lyxml_elem * next
Definition: xml.h:100
const struct lyxml_ns * ns
Definition: xml.h:78
struct lyxml_attr * attr
Definition: xml.h:98
const char * prefix
Definition: xml.h:62
struct lyxml_elem * child
Definition: xml.h:99
char flags
Definition: xml.h:93
struct lyxml_elem * parent
Definition: xml.h:61
const char * value
Definition: xml.h:63
const char * name
Definition: xml.h:79
struct lyxml_ns * next
Definition: xml.h:60
LYXML_ATTR_TYPE type
Definition: xml.h:59
const char * content
Definition: xml.h:105
struct lyxml_elem * prev
Definition: xml.h:101
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.
int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
struct lyxml_elem * lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root)
Duplicate the XML tree into the different content.
enum lyxml_attr_type LYXML_ATTR_TYPE
enumeration of attribute types
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.
int lyxml_print_file(FILE *stream, const struct lyxml_elem *elem, int options)
Dump XML tree to a IO stream.
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 * lyxml_get_attr(const struct lyxml_elem *elem, const char *name, const char *ns)
Get value of the attribute in the specified element.
lyxml_attr_type
enumeration of attribute types
Definition: xml.h:45
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...
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...
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 * lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options)
Parse XML from filesystem.
struct lyxml_elem * lyxml_parse_mem(struct ly_ctx *ctx, const char *data, int options)
Parse XML from in-memory string.
@ LYXML_ATTR_STD
Definition: xml.h:46
@ LYXML_ATTR_NS
Definition: xml.h:47
@ LYXML_ATTR_STD_UNRES
Definition: xml.h:48
Element's attribute definition.
Definition: xml.h:75
Structure describing an element in an XML tree.
Definition: xml.h:92
Namespace definition.
Definition: xml.h:58