libyang
1.0.253
YANG data modeling language library
|
Modules | |
XML parser options | |
XML printer options | |
Data Structures | |
struct | lyxml_ns |
Namespace definition. More... | |
struct | lyxml_attr |
Element's attribute definition. More... | |
struct | lyxml_elem |
Structure describing an element in an XML tree. More... | |
Typedefs | |
typedef enum lyxml_attr_type | LYXML_ATTR_TYPE |
enumeration of attribute types More... | |
Enumerations | |
enum | lyxml_attr_type { LYXML_ATTR_STD = 1, LYXML_ATTR_NS = 2, LYXML_ATTR_STD_UNRES = 3 } |
enumeration of attribute types More... | |
Functions | |
struct lyxml_elem * | lyxml_parse_mem (struct ly_ctx *ctx, const char *data, int options) |
Parse XML from in-memory string. More... | |
struct lyxml_elem * | lyxml_parse_path (struct ly_ctx *ctx, const char *filename, int options) |
Parse XML from filesystem. More... | |
int | lyxml_print_file (FILE *stream, const struct lyxml_elem *elem, int options) |
Dump XML tree to a IO stream. More... | |
int | lyxml_print_fd (int fd, const struct lyxml_elem *elem, int options) |
Dump XML tree to a IO stream. More... | |
int | lyxml_print_mem (char **strp, const struct lyxml_elem *elem, int options) |
Dump XML tree to a IO stream. More... | |
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. More... | |
struct lyxml_elem * | lyxml_dup (struct ly_ctx *ctx, struct lyxml_elem *root) |
Duplicate the XML tree into the different content. More... | |
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 definitions. More... | |
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 definitions. In contrast to lyxml_free(), free also all the element's siblings (preceding as well as following). More... | |
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 manipulate with the elem. Any namespaces are corrected and copied, if needed. More... | |
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. More... | |
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. More... | |
Simplified libyang XML parser for XML data modeled by YANG.
struct lyxml_ns |
Namespace definition.
The structure is actually casted lyxml_attr structure which covers all attributes defined in an element. The namespace definition is in this case also covered by lyxml_attr structure.
Data Fields | ||
---|---|---|
LYXML_ATTR_TYPE | type |
type of the attribute = LYXML_ATTR_NS |
struct lyxml_ns * | next |
next sibling attribute |
struct lyxml_elem * | parent |
parent node of the attribute |
const char * | prefix |
the namespace prefix if defined, NULL for default namespace |
const char * | value |
the namespace value |
struct lyxml_attr |
Element's attribute definition.
The structure actually covers both the attributes as well as namespace definitions.
Attributes are being connected only into a singly linked list (compare it with the elements).
Data Fields | ||
---|---|---|
LYXML_ATTR_TYPE | type |
type of the attribute |
struct lyxml_attr * | next |
next sibling attribute |
struct lyxml_ns * | ns |
pointer to the namespace of the attribute if any |
const char * | name |
name of the attribute (the LocalPart of the qualified name) |
const char * | value |
data stored in the attribute |
struct lyxml_elem |
Structure describing an element in an XML tree.
If the name item is NULL, then the content is part of the mixed content.
Children elements are connected in a half ring doubly linked list:
Data Fields | ||
---|---|---|
char | flags |
special flags |
struct lyxml_elem * | parent |
parent node |
struct lyxml_attr * | attr |
first attribute declared in the element |
struct lyxml_elem * | child |
first children element |
struct lyxml_elem * | next |
next sibling node |
struct lyxml_elem * | prev |
previous sibling node |
const char * | name |
name of the element |
struct lyxml_ns * | ns |
namespace of the element |
const char * | content |
text content of the node if any |
typedef enum lyxml_attr_type LYXML_ATTR_TYPE |
enumeration of attribute types
enum lyxml_attr_type |
struct lyxml_elem* lyxml_parse_mem | ( | struct ly_ctx * | ctx, |
const char * | data, | ||
int | options | ||
) |
Parse XML from in-memory string.
[in] | ctx | libyang context to use |
[in] | data | Pointer to a NULL-terminated string containing XML data to parse. |
[in] | options | Parser options, see XML parser options. |
data
. To free the returned data, use lyxml_free(). In these cases, the function sets #ly_errno to LY_SUCCESS. In case of error, #ly_errno contains appropriate error code (see #LY_ERR). struct lyxml_elem* lyxml_parse_path | ( | struct ly_ctx * | ctx, |
const char * | filename, | ||
int | options | ||
) |
Parse XML from filesystem.
[in] | ctx | libyang context to use |
[in] | filename | Path to the file where read data to parse |
[in] | options | Parser options, see XML parser options. |
int lyxml_print_file | ( | FILE * | stream, |
const struct lyxml_elem * | elem, | ||
int | options | ||
) |
Dump XML tree to a IO stream.
To write data into a file descriptor instead of file stream, use lyxml_print_fd().
[in] | stream | IO stream to print out the tree. |
[in] | elem | Root element of the XML tree to print |
[in] | options | Dump options, see XML printer options. |
int lyxml_print_fd | ( | int | fd, |
const struct lyxml_elem * | elem, | ||
int | options | ||
) |
Dump XML tree to a IO stream.
Same as lyxml_dump(), but it writes data into the given file descriptor.
[in] | fd | File descriptor to print out the tree. |
[in] | elem | Root element of the XML tree to print |
[in] | options | Dump options, see XML printer options. |
int lyxml_print_mem | ( | char ** | strp, |
const struct lyxml_elem * | elem, | ||
int | options | ||
) |
Dump XML tree to a IO stream.
Same as lyxml_dump(), but it allocates memory and store the data into it. It is up to caller to free the returned string by free().
[out] | strp | Pointer to store the resulting dump. |
[in] | elem | Root element of the XML tree to print |
[in] | options | Dump options, see XML printer options. |
int lyxml_print_clb | ( | ssize_t(*)(void *arg, const void *buf, size_t count) | writeclb, |
void * | arg, | ||
const struct lyxml_elem * | elem, | ||
int | options | ||
) |
Dump XML tree to a IO stream.
Same as lyxml_dump(), but it writes data via the provided callback.
[in] | writeclb | Callback function to write the data (see write(1)). |
[in] | arg | Optional caller-specific argument to be passed to the writeclb callback. |
[in] | elem | Root element of the XML tree to print |
[in] | options | Dump options, see XML printer options. |
struct lyxml_elem* lyxml_dup | ( | struct ly_ctx * | ctx, |
struct lyxml_elem * | root | ||
) |
Duplicate the XML tree into the different content.
Date parser requires to have the input XML tree in the same context as the resulting data tree. Therefore, if you need to parse a single XML tree into a different contexts, you have to duplicate the source XML tree into the required context first.
[in] | ctx | Target context for the result. |
[in] | root | Root node of the XML tree to duplicate. If an internal node is provided, the parents are not duplicated and only the specified subtree is duplicated. |
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 definitions.
[in] | ctx | libyang context to use |
[in] | elem | Pointer to the element to free. |
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 definitions. In contrast to lyxml_free(), free also all the element's siblings (preceding as well as following).
[in] | ctx | libyang context to use |
[in] | elem | Pointer to the element to free. |
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 manipulate with the elem. Any namespaces are corrected and copied, if needed.
[in] | ctx | libyang context to use. |
[in] | elem | Element to unlink from its parent (if any). |
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_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.
[in] | elem | Element where start namespace searching |
[in] | prefix | Prefix of the namespace to search for |