<libroxml
version="3.0.2"
/>
|
header for libroxml.so More...
Go to the source code of this file.
Macros | |
#define | ROXML_API |
#define | ROXML_INVALID_NODE 0x000 |
#define | ROXML_ATTR_NODE 0x008 |
#define | ROXML_STD_NODE 0x010 |
#define | ROXML_ELM_NODE 0x010 |
#define | ROXML_TXT_NODE 0x020 |
#define | ROXML_CMT_NODE 0x040 |
#define | ROXML_PI_NODE 0x080 |
#define | ROXML_NS_NODE 0x100 |
#define | ROXML_NSDEF_NODE (ROXML_NS_NODE | ROXML_ATTR_NODE) |
#define | ROXML_CDATA_MOD 0x200 |
#define | ROXML_CDATA_NODE (ROXML_TXT_NODE | ROXML_CDATA_MOD) |
#define | ROXML_DOCTYPE_NODE 0x400 |
#define | ROXML_ALL_NODES (ROXML_PI_NODE | ROXML_CMT_NODE | ROXML_TXT_NODE | ROXML_ATTR_NODE | ROXML_ELM_NODE) |
#define | ROXML_ALL_NODE ROXML_ALL_NODES |
#define | ROXML_NODE_TYPES 0x05f8 |
#define | ROXML_ESCAPED_MOD 0x800 |
#define | ROXML_NON_ESCAPABLE_NODES (ROXML_CMT_NODE | ROXML_PI_NODE | ROXML_NS_NODE | ROXML_CDATA_MOD | ROXML_DOCTYPE_NODE) |
#define | ENCODE 0 |
#define | DECODE 1 |
#define | RELEASE_ALL (void*)-1 |
#define | RELEASE_LAST (void*)-2 |
#define | ROXML_INVALID_DOC (node_t*)0 |
Typedefs | |
typedef struct node | node_t |
node_t structure | |
Functions | |
ROXML_API node_t * | roxml_load_buf (char *buffer) |
load function for buffers | |
ROXML_API node_t * | roxml_load_doc (char *filename) |
load function for files | |
ROXML_API node_t * | roxml_load_fd (int fd) |
load function for file descriptors | |
ROXML_API void | roxml_close (node_t *n) |
unload function | |
ROXML_API node_t * | roxml_get_next_sibling (node_t *n) |
next sibling getter function | |
ROXML_API node_t * | roxml_get_prev_sibling (node_t *n) |
prev sibling getter function | |
ROXML_API node_t * | roxml_get_parent (node_t *n) |
parent getter function | |
ROXML_API node_t * | roxml_get_root (node_t *n) |
root getter function | |
ROXML_API node_t * | roxml_get_ns (node_t *n) |
namespace getter function | |
ROXML_API node_t * | roxml_set_ns (node_t *n, node_t *ns) |
namespace setter function | |
ROXML_API node_t * | roxml_get_cmt (node_t *n, int nth) |
comment getter function | |
ROXML_API int | roxml_get_cmt_nb (node_t *n) |
comments number getter function | |
ROXML_API node_t * | roxml_get_chld (node_t *n, char *name, int nth) |
chld getter function | |
ROXML_API int | roxml_get_chld_nb (node_t *n) |
chlds number getter function | |
ROXML_API node_t * | roxml_get_pi (node_t *n, int nth) |
process-instruction getter function | |
ROXML_API int | roxml_get_pi_nb (node_t *n) |
process-instruction number getter function | |
ROXML_API char * | roxml_get_name (node_t *n, char *buffer, int size) |
name getter function | |
ROXML_API char * | roxml_get_content (node_t *n, char *buffer, int bufsize, int *size) |
content getter function | |
ROXML_API int | roxml_escape (const char *buf, int decode, char *out) |
XML encoding/decoding function. | |
ROXML_API int | roxml_get_nodes_nb (node_t *n, int type) |
number of nodes getter function | |
ROXML_API node_t * | roxml_get_nodes (node_t *n, int type, char *name, int nth) |
nodes getter function | |
ROXML_API int | roxml_get_attr_nb (node_t *n) |
number of attribute getter function | |
ROXML_API node_t * | roxml_get_attr (node_t *n, char *name, int nth) |
attribute getter function | |
ROXML_API node_t ** | roxml_xpath (node_t *n, char *path, int *nb_ans) |
exec path function | |
ROXML_API int | roxml_get_type (node_t *n) |
node type function | |
ROXML_API int | roxml_get_node_position (node_t *n) |
node get position function | |
ROXML_API void | roxml_release (void *data) |
memory cleanning function | |
ROXML_API node_t * | roxml_add_node (node_t *parent, int position, int type, char *name, char *value) |
add a node to the tree | |
ROXML_API node_t * | roxml_get_txt (node_t *n, int nth) |
text node getter function | |
ROXML_API int | roxml_get_txt_nb (node_t *n) |
text node number getter function | |
ROXML_API void | roxml_del_node (node_t *n) |
node deletion function | |
ROXML_API int | roxml_commit_changes (node_t *n, char *dest, char **buffer, int human) |
sync function | |
ROXML_API int | roxml_commit_file (node_t *n, char *dest, int human) |
sync to named file function | |
ROXML_API int | roxml_commit_buffer (node_t *n, char **buffer, int human) |
sync to a memory buffer function | |
ROXML_API int | roxml_commit_fd (node_t *n, int fd, int human) |
sync to file descriptor function | |
header for libroxml.so
(C) Copyright 2014 Tristan Lelong trist.nosp@m.an.l.nosp@m.elong.nosp@m.@lib.nosp@m.roxml.nosp@m..net
SPDX-Licence-Identifier: LGPL-2.1+ The author added a static linking exception, see License.txt.
Definition in file roxml.h.
#define DECODE 1 |
constant for requesting unescape of a string.
#define ENCODE 0 |
constant for requesting escape of a string.
#define RELEASE_ALL (void*)-1 |
when used with roxml_release, release all memory allocated by current thread
#define RELEASE_LAST (void*)-2 |
when used with roxml_release, release last variable allocated
example:
#define ROXML_ALL_NODE ROXML_ALL_NODES |
constant for all types of nodes for backward compatibility
#define ROXML_ALL_NODES (ROXML_PI_NODE | ROXML_CMT_NODE | ROXML_TXT_NODE | ROXML_ATTR_NODE | ROXML_ELM_NODE) |
#define ROXML_ATTR_NODE 0x008 |
#define ROXML_CDATA_MOD 0x200 |
constant for cdata nodes modifier applied to ROXML_TXT_NODE.
#define ROXML_CDATA_NODE (ROXML_TXT_NODE | ROXML_CDATA_MOD) |
#define ROXML_CMT_NODE 0x040 |
#define ROXML_DOCTYPE_NODE 0x400 |
#define ROXML_ELM_NODE 0x010 |
#define ROXML_ESCAPED_MOD 0x800 |
constant for node modifier use to indicate escaped text.
#define ROXML_INVALID_DOC (node_t*)0 |
#define ROXML_NODE_TYPES 0x05f8 |
#define ROXML_NON_ESCAPABLE_NODES (ROXML_CMT_NODE | ROXML_PI_NODE | ROXML_NS_NODE | ROXML_CDATA_MOD | ROXML_DOCTYPE_NODE) |
constant for nodes that should not be escaped.
#define ROXML_NS_NODE 0x100 |
#define ROXML_NSDEF_NODE (ROXML_NS_NODE | ROXML_ATTR_NODE) |
constant for namespace definition nodes
#define ROXML_PI_NODE 0x080 |
constant for processing_intruction nodes
#define ROXML_STD_NODE 0x010 |
#define ROXML_TXT_NODE 0x020 |
ROXML_API node_t * roxml_add_node | ( | node_t * | parent, |
int | position, | ||
int | type, | ||
char * | name, | ||
char * | content | ||
) |
add a node to the tree
this function add a new node to the tree. This will not update de buffer or file, only the RAM loaded tree. One should call roxml_commit_changes to save modifications. If the parent node is an ROXML_ELM_NODE, then, new node will be added as a child. Else the node will be added as a sibling of the parent node. In the later case, position parameter describes the position in the sibling list, instead of position in the children list.
parent | the parent node |
position | the position as a child of parent 1 is the first child, 0 for auto position at the end of children list... |
type | the type of node between ROXML_ATTR_NODE, ROXML_ELM_NODE, ROXML_TXT_NODE, ROXML_CDATA_NODE, ROXML_PI_NODE, ROXML_CMT_NODE, ROXML_NSDEF_NODE, ROXML_NS_NODE. |
name | the name of the node (mandatory for ROXML_ATTR_NODE and ROXML_ELM_NODE and ROXML_PI_NODE and ROXML_NSDEF_NODE and ROXML_NS_NODE only) |
value | the text content (mandatory for ROXML_TXT_NODE, ROXML_CDATA_NODE, ROXML_CMT_NODE, ROXML_ATTR_NODE and ROXML_NSDEF_NODE optional for ROXML_ELM_NODE, ROXML_PI_NODE). The text content for an attribute is the attribute value |
Escaping the as per XML specifications can be done by adding the ROXML_ESCAPED_MOD modifier to node type as showed below:
This will create a node that exports as:
* <node1>content <that> needs escaping</node1> *
paramaters name and value depending on node type:
some examples to obtain this xml result file
<root> <!-- sample XML file --> <item id="42"> <price> 24 </price> </item> </root>
Or also:
If you need a valid XML doc, just start by adding a corresponding process-instruction. Example, to obtain this xml file:
<?xml version="1.0" encoding="UTF-8"?> <!--sample file--> <doc> basic content <item/> <item/> <item/> </doc>
Definition at line 353 of file roxml_edit.c.
unload function
This function clear a document and all the corresponding nodes It release all memory allocated during roxml_load_doc or roxml_load_file or roxml_add_node. All nodes from the tree are not available anymore.
n | is any node of the tree to be cleaned |
Definition at line 25 of file roxml_core.c.
sync to a memory buffer function
this function syncs changes from the RAM tree to the given buffer in human or one-line format The tree will be processed starting with the root node 'n' and following with all its children or if n is the root, all its siblings and children. The tree will be dumped to a buffer if 'buffer' is not null. the buffer is allocated by the library and a pointer to it will be stored into 'buffer'. The allocated buffer can be freed using free()
n | the root node of the tree to write |
buffer | the address of a buffer where the tree will be written. This buffer have to be freed after use |
human | 0 for one-line tree, or 1 for human format (using indentation, newlines...) |
One should do:
to generate the following xml bloc:
<root> <!-- sample XML file --> <item id="42"> <price> 24 </price> </item> </root>
or also
to generate the following xml bloc:
<root><!-- sample XML file --><item id="42"><price>24</price></item></root>
Definition at line 296 of file roxml_commit.c.
sync function
This function is now deprecated and one should use roxml_commit_buffer or roxml_commit_file that achieves the exact same goal.
n | the root node of the tree to write |
dest | the path to a file to write tree to |
buffer | the address of a buffer where the tree will be written. This buffer have to be freed after use |
human | 0 for one-line tree, or 1 for human format (using tabs, newlines...) |
This is a legacy function that proposes the same functionnalities as both roxml_commit_file
and roxml_commit_buffer
. New code should use the latter functions when needed.
One should do:
to generate the following xml bloc:
<root> <!-- sample XML file --> <item id="42"> <price> 24 </price> </item> </root>
or also
to generate the following xml bloc:
<root><!-- sample XML file --><item id="42"><price>24</price></item></root>
the buffer variant works more or less the same way
to generate the following xml bloc:
<root><!-- sample XML file --><item id="42"><price>24</price></item></root>
Definition at line 357 of file roxml_commit.c.
sync to file descriptor function
this function synchronizes changes from the RAM tree to the given file in human or one-line format. The tree will be processed starting with the root node 'n' and following with all its children or if n is the root, all its siblings and children. The tree will be dumped to a file if fd is a valid file descriptor.
n | the root node of the tree to write |
fd | the file descriptor to write tree to |
human | 0 for one-line tree, or 1 for human format (using tabs, newlines...) |
The file described by fd is not truncated so this function allows one to append an XML subtree to an existing file.
One should do:
to generate the following xml bloc:
<root> <!-- sample XML file --> <item id="42"> <price> 24 </price> </item> </root>
or also
to generate the following xml bloc:
<root><!-- sample XML file --><item id="42"><price>24</price></item></root>
Definition at line 317 of file roxml_commit.c.
sync to named file function
this function sync changes from the RAM tree to the given file in human or one-line format The tree will be processed starting with the root node 'n' and following with all its children or if n is the root, all its siblings and children. The tree will be dumped to a file if 'dest' is not null and contains a valid path.
n | the root node of the tree to write |
dest | the path to a file to write tree to |
human | 0 for one-line tree, or 1 for human format (using tabs, newlines...) |
One should do:
to generate the following xml bloc:
<root> <!-- sample XML file --> <item id="42"> <price> 24 </price> </item> </root>
or also
to generate the following xml bloc:
<root><!-- sample XML file --><item id="42"><price>24</price></item></root>
Definition at line 272 of file roxml_commit.c.
node deletion function
this function delete a node from the tree. The node is not really deleted from the file or buffer until the roxml_commit_changes is called, but it won't be visible anymore in the XML tree.
n | the node to delete |
Definition at line 204 of file roxml_edit.c.
ROXML_API int roxml_escape | ( | const char * | buf, |
int | decode, | ||
char * | out | ||
) |
XML encoding/decoding function.
this function converts the escape codes into ascii char or special carachers in escape codes.
buf | the bytes to be converted |
decode | indicates whether to encde or decode escape caracteres. |
out | is filled with the encoded/decoded data if not null. |
Definition at line 31 of file roxml_content.c.
attribute getter function
This function get the nth attribute of a node.
n | is one node of the tree |
name | is the name of the attribute to get |
nth | the id of attribute to read |
example: given the following xml file
<xml> <product id="42" class="item"/> </xml>
Definition at line 444 of file roxml_content.c.
number of attribute getter function
This function returns the number of attributes for a given node
n | is one node of the tree |
Definition at line 439 of file roxml_content.c.
chld getter function
This function returns a given chld of a node etheir by name, or the nth child.
n | is one node of the tree |
name | is the name of the child to get |
nth | is the id of the chld to get |
example: given the following xml file
<xml> <item1/> <item2/> <item3/> </xml>
Definition at line 454 of file roxml_content.c.
chlds number getter function
This function return the number of chlidren for a given node
n | is one node of the tree |
Definition at line 449 of file roxml_content.c.
comment getter function
This function returns the nth comment of a node
n | is one node of the tree |
nth | is the id of the cmt to get |
example: given the following xml file
<xml> <item1/> <!--comment1--> <!--comment2--> <item2/> <item3/> </xml>
Definition at line 424 of file roxml_content.c.
comments number getter function
This function return the number of comments for a given node
n | is one node of the tree |
Definition at line 419 of file roxml_content.c.
content getter function
This function returns the content of a node.; if the returned pointer is NULL then the node either has no content or this function is irrelevant for this kind of node. depending on node type it will return:
returned string should be freed using roxml_release when not used anymore
n | is one node of the tree |
buffer | is the buffer where result will be written or NULL for internal allocation |
bufsize | the size if using custom buffer |
size | the actual size of copied result. returned size should be less that buffer size since roxml_get_content will add the \0. if buffer was not NULL and size == buf_size, then given buffer was too small and node content was truncated |
Definition at line 148 of file roxml_content.c.
name getter function
This function return the name of the node or fill the current buffer with it if not NULL. if name is NULL, the function will allocate a buffer that user should free using roxml_release when no longer needed. depending on node type it will return:
Be carreful as if your buffer is too short for the returned string, it will be truncated
n | is one node of the tree |
buffer | a buffer pointer or NULL if has to be auto allocated |
size | the size of buffer pointed by buffer if not NULL |
Definition at line 225 of file roxml_content.c.
next sibling getter function
This function returns the next sibling of a given node
n | is one node of the tree |
Definition at line 34 of file roxml_nav.c.
node get position function
This function tells the index of a node between all its siblings homonyns.
n | is the node to test |
Definition at line 466 of file roxml_content.c.
nodes getter function
This function get the nth node matching type contained in a node, or the first node named name. All other roxml_get_* are wrapper to this function. When asking for several node type (let say ROXML_ALL_NODES), all ROXML_ATTR_NODE will be placed first, then, all other nodes will come mixed, depending on xml document order.
n | is one node of the tree |
type | is the bitmask of node types we want to consider |
name | is the name of the child to get. This parameter is only relevant for node with types: ROXML_ELM_NODE, ROXML_ATTR_NODE, ROXML_PI_NODE |
nth | the id of attribute to read |
Definition at line 394 of file roxml_content.c.
number of nodes getter function
This function returns the number of nodes matching type flag contained in a given node all other roxml_get_*_nb are wrapper to this
n | is one node of the tree |
type | is the bitmask of node types we want to consider |
example: given the following xml file
<xml> <!-- comment --> <?value="2"?> <product id="42" class="item"/> <product id="43" class="item"/> </xml>
Definition at line 308 of file roxml_content.c.
namespace getter function
This function returns the namespace of a node
n | is one node of the tree |
example: given the following xml file
<xml xmlns:test="http://www.test.org"> <test:item1 test:value1="3"/> </xml>
Definition at line 404 of file roxml_content.c.
parent getter function
This function returns the parent of a given node
n | is one node of the tree |
Definition at line 45 of file roxml_nav.c.
process-instruction getter function
This function returns the nth process-instruction of a node.
n | is one node of the tree |
nth | is the id of the pi to get |
example: given the following xml file
<xml> <item1/> <?test value="2"?> <?test param="3"?> <item2/> <item3/> </xml>
Definition at line 414 of file roxml_content.c.
process-instruction number getter function
This function return the number of process-instruction in a given node
n | is one node of the tree |
Definition at line 409 of file roxml_content.c.
prev sibling getter function
This function returns the prev sibling of a given node
n | is one node of the tree |
Definition at line 14 of file roxml_nav.c.
root getter function
This function returns the root of a tree containing the given node The root is defined as a virtual node that contains all first rank nodes if document is not a valid xml document:
<data1> <item/> <item/> </data1> <data2> <item/> <item/> </data2>
will be processed successfully and the root node will have 2 children: data1 and data2
if document was:
<?xml version="1.0"> <doc> <data1> <item/> <item/> </data1> <data2> <item/> <item/> </data2> </doc>
In this case, the node "doc" will be the root, and will contain 2 children: data1 and data2
For a document to be valid, following conditions must be met:
n | is one node of the tree |
Definition at line 55 of file roxml_nav.c.
text node getter function
this function return the text content of a node as a ROXML_TXT_NODE the content of the text node can be read using the roxml_get_content function
n | the node that contains text |
nth | the nth text node to retrieve |
example: given this xml file:
<xml> This is <item/> an example <item/> of text nodes </xml>
Definition at line 434 of file roxml_content.c.
text node number getter function
this function return the number of text nodes in a standard node
n | the node to search into |
Definition at line 429 of file roxml_content.c.
node type function
This function tells if a node is an ROXML_ATTR_NODE, ROXML_TXT_NODE, ROXML_PI_NODE, ROXML_CMT_NODE or ROXML_ELM_NODE. Warning: ROXML_CDATA_NODE are special. They return a type as ROXML_TXT_NODE.
n | is the node to test |
Definition at line 459 of file roxml_content.c.
load function for buffers
This function load a document by parsing all the corresponding nodes. The document must be contained inside the char * buffer given in parameter and remain valid until the roxml_close() function is called
buffer | the XML buffer to load |
Definition at line 47 of file roxml_buff.c.
load function for files
This function load a file document by parsing all the corresponding nodes
filename | the XML document to load |
Definition at line 90 of file roxml_file.c.
load function for file descriptors
This function load a document by parsing all the corresponding nodes
fd | the opened file descriptor to XML document to load |
Definition at line 73 of file roxml_file.c.
roxml_release | ( | void * | data | ) |
memory cleanning function
This function release the memory pointed by pointer just like free would but for memory allocated with roxml_malloc. Freeing a NULL pointer won't do anything. roxml_release also allow you to remove all previously allocated memory by using RELEASE_ALL as argument. You can also safely use RELEASE_LAST argument that will release the previously allocated varable within the current thread (making this function thread safe). if using roxml_release on a variable non roxml_mallocated, nothing will happen (ie variable won't be freed)
data | the pointer to delete or NULL or RELEASE_ALL or RELEASE_LAST |
Definition at line 109 of file roxml_mem.c.
namespace setter function
This function set the namespace of a node to the given namespace definition. The namespace must be previously defined in the xml tree in an ancestor of node n.
n | is one node of the tree |
ns | is one nsdef node of the tree |
Definition at line 395 of file roxml_edit.c.
roxml_xpath | ( | node_t * | n, |
char * | path, | ||
int * | nb_ans | ||
) |
exec path function
This function return a node set (table of nodes) corresponding to a given xpath. resulting node set should be roxml_release when not used anymore (but not individual nodes)
n | is one node of the tree |
path | the xpath to use |
nb_ans | the number of results |
handled xpath are described in xpath handling
Definition at line 167 of file roxml_stub.c.