Fri Nov 12 12:11:09 2010

Asterisk developer's documentation


xml.h File Reference

Asterisk XML abstraction layer. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define AST_XML_DOCS

Functions

void ast_xml_close (struct ast_xml_doc *doc)
 Close an already open document and free the used structure.
struct ast_xml_node * ast_xml_find_element (struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
 Find a node element by name.
int ast_xml_finish (void)
 Cleanup library allocated global data.
void ast_xml_free_attr (const char *attribute)
 Free an attribute returned by ast_xml_get_attribute().
void ast_xml_free_node (struct ast_xml_node *node)
 Free node.
void ast_xml_free_text (const char *text)
 Free a content element that was returned by ast_xml_get_text().
const char * ast_xml_get_attribute (struct ast_xml_node *node, const char *attrname)
 Get a node attribute by name.
struct ast_xml_node * ast_xml_get_root (struct ast_xml_doc *doc)
 Get the document root node.
const char * ast_xml_get_text (struct ast_xml_node *node)
 Get an element content string.
int ast_xml_init (void)
 Initialize the XML library implementation. This function is used to setup everything needed to start working with the xml implementation.
struct ast_xml_node * ast_xml_node_get_children (struct ast_xml_node *node)
 Get the node's children.
const char * ast_xml_node_get_name (struct ast_xml_node *node)
 Get the name of a node.
struct ast_xml_node * ast_xml_node_get_next (struct ast_xml_node *node)
 Get the next node in the same level.
struct ast_xml_node * ast_xml_node_get_parent (struct ast_xml_node *node)
 Get the parent of a specified node.
struct ast_xml_node * ast_xml_node_get_prev (struct ast_xml_node *node)
 Get the previous node in the same leve.
struct ast_xml_doc * ast_xml_open (char *filename)
 Open an XML document.

Detailed Description

Asterisk XML abstraction layer.

Definition in file xml.h.


Define Documentation

#define AST_XML_DOCS

Definition at line 118 of file xml.h.


Function Documentation

void ast_xml_close ( struct ast_xml_doc *  doc  ) 

Close an already open document and free the used structure.

Return values:
doc The document reference.

Definition at line 73 of file xml.c.

Referenced by ast_xmldoc_load_documentation(), and xmldoc_unload_documentation().

00074 {
00075    if (!doc) {
00076       return;
00077    }
00078 
00079    xmlFreeDoc((xmlDoc *) doc);
00080    doc = NULL;
00081 }

struct ast_xml_node* ast_xml_find_element ( struct ast_xml_node *  root_node,
const char *  name,
const char *  attrname,
const char *  attrvalue 
) [read]

Find a node element by name.

Parameters:
node This is the node starting point.
name Node name to find.
attrname attribute name to match (if NULL it won't be matched).
attrvalue attribute value to match (if NULL it won't be matched).
Return values:
NULL if not found
The node on success.

Definition at line 138 of file xml.c.

References ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_name(), and ast_xml_node_get_next().

Referenced by xmldoc_build_field(), and xmldoc_get_node().

00139 {
00140    struct ast_xml_node *cur;
00141    const char *attr;
00142 
00143    if (!root_node) {
00144       return NULL;
00145    }
00146 
00147    for (cur = root_node; cur; cur = ast_xml_node_get_next(cur)) {
00148       /* Check if the name matchs */
00149       if (strcmp(ast_xml_node_get_name(cur), name)) {
00150          continue;
00151       }
00152       /* We need to check for a specific attribute name? */
00153       if (!attrname || !attrvalue) {
00154          return cur;
00155       }
00156       /* Get the attribute, we need to compare it. */
00157       if ((attr = ast_xml_get_attribute(cur, attrname))) {
00158          /* does attribute name/value matches? */
00159          if (!strcmp(attr, attrvalue)) {
00160             ast_xml_free_attr(attr);
00161             return cur;
00162          }
00163          ast_xml_free_attr(attr);
00164       }
00165    }
00166 
00167    return NULL;
00168 }

int ast_xml_finish ( void   ) 

Cleanup library allocated global data.

Return values:
0 On success.
1 On error.

Definition at line 46 of file xml.c.

Referenced by xmldoc_unload_documentation().

00047 {
00048    xmlCleanupParser();
00049 
00050    return 0;
00051 }

void ast_xml_free_attr ( const char *  attribute  ) 

Free an attribute returned by ast_xml_get_attribute().

Parameters:
data pointer to be freed.

Definition at line 107 of file xml.c.

Referenced by ast_xml_find_element(), ast_xmldoc_build_seealso(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

00108 {
00109    if (attribute) {
00110       xmlFree((char *) attribute);
00111    }
00112 }

void ast_xml_free_node ( struct ast_xml_node *  node  ) 

Free node.

Parameters:
node Node to be released.

Definition at line 97 of file xml.c.

00098 {
00099    if (!node) {
00100       return;
00101    }
00102 
00103    xmlFreeNode((xmlNode *) node);
00104    node = NULL;
00105 }

void ast_xml_free_text ( const char *  text  ) 

Free a content element that was returned by ast_xml_get_text().

Parameters:
text text to be freed.

Definition at line 114 of file xml.c.

Referenced by ast_xmldoc_build_seealso(), xmldoc_get_formatted(), xmldoc_parse_para(), and xmldoc_parse_variable().

00115 {
00116    if (text) {
00117       xmlFree((char *) text);
00118    }
00119 }

const char* ast_xml_get_attribute ( struct ast_xml_node *  node,
const char *  attrname 
)

Get a node attribute by name.

Parameters:
node Node where to search the attribute.
attrname Attribute name.
Return values:
NULL on error
The attribute value on success.

Definition at line 121 of file xml.c.

Referenced by ast_xml_find_element(), ast_xmldoc_build_seealso(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

00122 {
00123    xmlChar *attrvalue;
00124 
00125    if (!node) {
00126       return NULL;
00127    }
00128 
00129    if (!attrname) {
00130       return NULL;
00131    }
00132 
00133    attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
00134 
00135    return (const char *) attrvalue;
00136 }

struct ast_xml_node* ast_xml_get_root ( struct ast_xml_doc *  doc  )  [read]

Get the document root node.

Parameters:
doc Document reference
Return values:
NULL on error
The root node on success.

Definition at line 84 of file xml.c.

Referenced by ast_xmldoc_load_documentation(), and xmldoc_get_node().

00085 {
00086    xmlNode *root_node;
00087 
00088    if (!doc) {
00089       return NULL;
00090    }
00091 
00092    root_node = xmlDocGetRootElement((xmlDoc *) doc);
00093 
00094    return (struct ast_xml_node *) root_node;
00095 }

const char* ast_xml_get_text ( struct ast_xml_node *  node  ) 

Get an element content string.

Parameters:
node Node from where to get the string.
Return values:
NULL on error.
The text content of node.

Definition at line 170 of file xml.c.

Referenced by ast_xmldoc_build_seealso(), xmldoc_get_formatted(), xmldoc_parse_para(), and xmldoc_parse_variable().

00171 {
00172    if (!node) {
00173       return NULL;
00174    }
00175 
00176    return (const char *) xmlNodeGetContent((xmlNode *) node);
00177 }

int ast_xml_init ( void   ) 

Initialize the XML library implementation. This function is used to setup everything needed to start working with the xml implementation.

Return values:
0 On success.
1 On error.

Definition at line 39 of file xml.c.

Referenced by ast_xmldoc_load_documentation().

00040 {
00041    LIBXML_TEST_VERSION
00042 
00043    return 0;
00044 }

struct ast_xml_node* ast_xml_node_get_children ( struct ast_xml_node *  node  )  [read]
const char* ast_xml_node_get_name ( struct ast_xml_node *  node  ) 
struct ast_xml_node* ast_xml_node_get_next ( struct ast_xml_node *  node  )  [read]
struct ast_xml_node* ast_xml_node_get_parent ( struct ast_xml_node *  node  )  [read]

Get the parent of a specified node.

Definition at line 199 of file xml.c.

00200 {
00201    return (struct ast_xml_node *) ((xmlNode *) node)->parent;
00202 }

struct ast_xml_node* ast_xml_node_get_prev ( struct ast_xml_node *  node  )  [read]

Get the previous node in the same leve.

Definition at line 194 of file xml.c.

00195 {
00196    return (struct ast_xml_node *) ((xmlNode *) node)->prev;
00197 }

struct ast_xml_doc* ast_xml_open ( char *  filename  )  [read]

Open an XML document.

Parameters:
filename Document path.
Return values:
NULL on error.
The ast_xml_doc reference to the open document.

Definition at line 53 of file xml.c.

Referenced by ast_xmldoc_load_documentation().

00054 {
00055    xmlDoc *doc;
00056 
00057    if (!filename) {
00058       return NULL;
00059    }
00060 
00061    doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
00062    if (doc) {
00063       /* process xinclude elements. */
00064       if (xmlXIncludeProcess(doc) < 0) {
00065          xmlFreeDoc(doc);
00066          return NULL;
00067       }
00068    }
00069 
00070    return (struct ast_xml_doc *) doc;
00071 }


Generated by  doxygen 1.6.2