e2k-xml-utils

## e2k-xml-utils e2k-xml-utils — XML utility functions |

## Synopsis

    xmlDoc*     e2k_parse_xml                   (const char *buf,
                                                 int len);
    xmlDoc*     e2k_parse_html                  (const char *buf,
                                                 int len);
    #define     E2K_IS_NODE                     (node, nspace, nname)

    #define     E2K_XML_HEADER
    void        e2k_g_string_append_xml_escaped (GString *string,
                                                 const char *value);

    xmlNode*    e2k_xml_find                    (xmlNode *node,
                                                 const char *name);
    xmlNode*    e2k_xml_find_in                 (xmlNode *node,
                                                 xmlNode *top,
                                                 const char *name);

## Description

## Details

### e2k_parse_xml ()

    xmlDoc*     e2k_parse_xml                   (const char *buf,
                                                 int len);

Parses the XML document in `buf`.

`buf` : | the data to parse
`len` : | the length of the buffer, or -1 if it is '\0'-terminated
Returns : | a pointer to an xmlDoc

### e2k_parse_html ()

    xmlDoc*     e2k_parse_html                  (const char *buf,
                                                 int len);

Parses the HTML document in `buf`.

`buf` : | the data to parse
`len` : | the length of the buffer, or -1 if it is '\0'-terminated
Returns : | a pointer to an xmlDoc

### E2K_IS_NODE()

    #define E2K_IS_NODE(node, nspace, nname) (!strcmp (node->name, nname) && node->ns && !strcmp (node->ns->href, nspace))

Utility macro for checking the name and namespace of an xmlNode.

`node` : | an xmlNode
`nspace` : | the namespace name
`nname` : | the non-namespace portion of the name
Returns : | `TRUE` if `node`'s name and namespace match `nname` and `nspace`

### E2K_XML_HEADER

    #define E2K_XML_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"

This can be used when creating an XML document

### e2k_g_string_append_xml_escaped ()

    void        e2k_g_string_append_xml_escaped (GString *string,
                                                 const char *value);

Appends `value` to `string`, escaping any characters that can't appear unencoded in XML text (eg, "<").

`string` : | a `GString` containing XML data
`value` : | data to append to `string`

### e2k_xml_find ()

    xmlNode*    e2k_xml_find                    (xmlNode *node,
                                                 const char *name);

Starts or continues a pre-order depth-first search of an xml document for an element named `name`. `node` is used as the starting point of the search, but is not examined itself.

To search the complete document, pass the root node of the document as `node` on the first call, and then on each successive call, pass the previous match as `node`.

`node` : | a node of an xml document
`name` : | the name of the element to find
Returns : | the first matching element after `node`, or `NULL` when there are no more matches.

### e2k_xml_find_in ()

    xmlNode*    e2k_xml_find_in                 (xmlNode *node,
                                                 xmlNode *top,
                                                 const char *name);

Starts or continues a pre-order depth-first search of a subset of an xml document for an element named `name`. `node` is used as the starting point of the search, but is not examined itself. `top` is the upper-most node that will be examined.

To search the complete tree under a given node, pass that node as both `node` and `top` on the first call, and then on each successive call, pass the previous match as `node` (with the original node still as `top`).

`node` : | a node of an xml document
`top` : | top of the search space
`name` : | the name of the element to find
Returns : | the first matching element after `node`, or `NULL` when there are no more matches.