34 #if defined(HAVE_LIBXML2)
35 #include <libxml/parser.h>
36 #include <libxml/tree.h>
37 #include <libxml/xinclude.h>
63 doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
66 if (xmlXIncludeProcess(doc) < 0) {
72 return (
struct ast_xml_doc *) doc;
79 doc = xmlNewDoc((
const xmlChar *)
"1.0");
80 return (
struct ast_xml_doc *) doc;
90 node = xmlNewNode(NULL, (
const xmlChar *) name);
92 return (
struct ast_xml_node *) node;
99 if (!parent || !child_name) {
103 child = xmlNewChild((xmlNode *) parent, NULL, (
const xmlChar *) child_name, NULL);
104 return (
struct ast_xml_node *) child;
109 if (!parent || !child) {
112 return (
struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
123 if (!(doc = xmlParseMemory(buffer, (
int) size))) {
125 if (xmlXIncludeProcess(doc) < 0) {
131 return (
struct ast_xml_doc *) doc;
140 xmlFreeDoc((xmlDoc *) doc);
150 xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
161 root_node = xmlDocGetRootElement((xmlDoc *) doc);
163 return (
struct ast_xml_node *) root_node;
172 xmlFreeNode((xmlNode *) node);
179 xmlFree((
char *) attribute);
186 xmlFree((
char *) text);
202 attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
204 return (
const char *) attrvalue;
209 if (!name || !value) {
213 if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
220 struct ast_xml_node *
ast_xml_find_element(
struct ast_xml_node *root_node,
const char *
name,
const char *attrname,
const char *attrvalue)
222 struct ast_xml_node *cur;
235 if (!attrname || !attrvalue) {
241 if (!strcmp(attr, attrvalue)) {
258 return (
struct ast_xml_doc *) ((xmlNode *)node)->doc;
262 xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
263 return (
struct ast_xml_ns *) ns;
268 return (
const char *) ((xmlNsPtr) ns)->href;
277 return (
const char *) xmlNodeGetContent((xmlNode *) node);
282 if (!node || !content) {
286 xmlNodeSetContent((xmlNode *) node, (
const xmlChar *) content);
291 return xmlDocDump(output, (xmlDocPtr)doc);
296 return (
const char *) ((xmlNode *) node)->name;
301 return (
struct ast_xml_node *) ((xmlNode *) node)->children;
306 return (
struct ast_xml_node *) ((xmlNode *) node)->next;
311 return (
struct ast_xml_node *) ((xmlNode *) node)->prev;
316 return (
struct ast_xml_node *) ((xmlNode *) node)->parent;
Asterisk main include file. File version handling, generic pbx functions.
int ast_xml_init(void)
Initialize the XML library implementation. This function is used to setup everything needed to start ...
const char * ast_xml_get_ns_href(struct ast_xml_ns *ns)
struct ast_xml_doc * ast_xml_open(char *filename)
Open an XML document.
struct ast_xml_doc * ast_xml_new(void)
Create a XML document.
void ast_xml_free_node(struct ast_xml_node *node)
Free node.
struct ast_xml_node * ast_xml_add_child(struct ast_xml_node *parent, struct ast_xml_node *child)
Add a child node, to a specified parent node.
int ast_xml_doc_dump_file(FILE *output, struct ast_xml_doc *doc)
Dump the specified document to a file.
struct ast_xml_node * ast_xml_get_root(struct ast_xml_doc *doc)
Get the document root node.
struct ast_xml_node * ast_xml_new_child(struct ast_xml_node *parent, const char *child_name)
Add a child node inside a passed parent node.
struct ast_xml_doc * ast_xml_get_doc(struct ast_xml_node *node)
Get the document based on a node.
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
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.
struct ast_xml_node * ast_xml_new_node(const char *name)
Create a XML node.
Asterisk XML abstraction layer.
void ast_xml_set_root(struct ast_xml_doc *doc, struct ast_xml_node *node)
Specify the root node of a XML document.
void ast_xml_set_text(struct ast_xml_node *node, const char *content)
Set an element content string.
struct ast_xml_node * ast_xml_node_get_parent(struct ast_xml_node *node)
Get the parent of a specified node.
void ast_xml_close(struct ast_xml_doc *doc)
Close an already open document and free the used structure.
Support for logging to various files, console and syslog Configuration in file logger.conf.
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value)
Set an attribute to a node.
const char * ast_xml_get_text(struct ast_xml_node *node)
Get an element content string.
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_read_memory(char *buffer, size_t size)
Open an XML document that resides in memory.
struct ast_xml_ns * ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name)
struct ast_xml_node * ast_xml_node_get_next(struct ast_xml_node *node)
Get the next node in the same level.
int ast_xml_finish(void)
Cleanup library allocated global data.
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.
void ast_xml_free_text(const char *text)
Free a content element that was returned by ast_xml_get_text()
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.