34 #if defined(HAVE_LIBXML2) 35 #include <libxml/parser.h> 36 #include <libxml/tree.h> 37 #include <libxml/xinclude.h> 38 #include <libxml/xpath.h> 41 #include <libxslt/xsltInternals.h> 42 #include <libxslt/transform.h> 56 #ifdef HAVE_LIBXSLT_CLEANUP 71 doc = xmlReadFile(filename,
NULL, XML_PARSE_RECOVER);
77 if (xmlXIncludeProcess(doc) < 0) {
84 xsltStylesheetPtr xslt = xsltLoadStylesheetPI(doc);
86 xmlDocPtr tmpdoc = xsltApplyStylesheet(xslt, doc,
NULL);
87 xsltFreeStylesheet(xslt);
96 ast_log(
LOG_NOTICE,
"XSLT support not found. XML documentation may be incomplete.\n");
100 xmlXPathOrderDocElems(doc);
102 return (
struct ast_xml_doc *) doc;
109 doc = xmlNewDoc((
const xmlChar *)
"1.0");
110 return (
struct ast_xml_doc *) doc;
120 node = xmlNewNode(
NULL, (
const xmlChar *) name);
122 return (
struct ast_xml_node *) node;
129 if (!parent || !child_name) {
133 child = xmlNewChild((xmlNode *) parent,
NULL, (
const xmlChar *) child_name,
NULL);
134 return (
struct ast_xml_node *) child;
139 if (!parent || !child) {
142 return (
struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
147 if (!parent || !child) {
150 return (
struct ast_xml_node *) xmlAddChildList((xmlNode *) parent, (xmlNode *) child);
158 return (
struct ast_xml_node *) xmlCopyNodeList((xmlNode *) list);
169 if (!(doc = xmlParseMemory(buffer, (
int) size))) {
171 if (xmlXIncludeProcess(doc) < 0) {
177 return (
struct ast_xml_doc *) doc;
186 xmlFreeDoc((xmlDoc *) doc);
196 xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
207 root_node = xmlDocGetRootElement((xmlDoc *) doc);
209 return (
struct ast_xml_node *) root_node;
218 xmlFreeNode((xmlNode *) node);
225 xmlFree((
char *) attribute);
232 xmlFree((
char *) text);
248 attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
250 return (
const char *) attrvalue;
255 if (!name || !value) {
259 if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
266 struct ast_xml_node *
ast_xml_find_element(
struct ast_xml_node *root_node,
const char *
name,
const char *attrname,
const char *attrvalue)
268 struct ast_xml_node *cur;
281 if (!attrname || !attrvalue) {
287 if (!strcmp(attr, attrvalue)) {
304 return (
struct ast_xml_doc *) ((xmlNode *)node)->doc;
308 xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
309 return (
struct ast_xml_ns *) ns;
314 return (
const char *) ((xmlNsPtr) ns)->href;
323 return (
const char *) xmlNodeGetContent((xmlNode *) node);
328 if (!node || !content) {
332 xmlNodeSetContent((xmlNode *) node, (
const xmlChar *) content);
337 return xmlDocDump(output, (xmlDocPtr)doc);
342 return (
const char *) ((xmlNode *) node)->name;
347 return (
struct ast_xml_node *) ((xmlNode *) node)->children;
352 return (
struct ast_xml_node *) ((xmlNode *) node)->next;
357 return (
struct ast_xml_node *) ((xmlNode *) node)->prev;
362 return (
struct ast_xml_node *) ((xmlNode *) node)->parent;
367 return (
struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[0];
372 xmlXPathFreeObject((xmlXPathObjectPtr) results);
377 return ((xmlXPathObjectPtr) results)->nodesetval->nodeNr;
380 struct ast_xml_xpath_results *
ast_xml_query(
struct ast_xml_doc *doc,
const char *xpath_str)
384 if (!(context = xmlXPathNewContext((xmlDoc *) doc))) {
388 result = xmlXPathEvalExpression((xmlChar *) xpath_str, context);
389 xmlXPathFreeContext(context);
394 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
395 xmlXPathFreeObject(result);
396 ast_debug(5,
"No results for query: %s\n", xpath_str);
399 return (
struct ast_xml_xpath_results *)
result;
const char * ast_xml_get_text(struct ast_xml_node *node)
Get an element content string.
Asterisk main include file. File version handling, generic pbx functions.
void ast_xml_free_text(const char *text)
Free a content element that was returned by ast_xml_get_text()
struct ast_xml_doc * ast_xml_new(void)
Create a XML document.
struct ast_xml_xpath_results * ast_xml_query(struct ast_xml_doc *doc, const char *xpath_str)
Execute an XPath query on an XML document.
void ast_xml_xpath_results_free(struct ast_xml_xpath_results *results)
Free the XPath results.
void ast_xml_set_text(struct ast_xml_node *node, const char *content)
Set an element content string.
int ast_xml_init(void)
Initialize the XML library implementation. This function is used to setup everything needed to start ...
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.
int ast_xml_xpath_num_results(struct ast_xml_xpath_results *results)
Return the number of results from an XPath query.
struct ast_xml_node * ast_xml_copy_node_list(struct ast_xml_node *list)
Create a copy of a n ode list.
const char * ast_xml_get_ns_href(struct ast_xml_ns *ns)
void ast_xml_close(struct ast_xml_doc *doc)
Close an already open document and free the used structure.
struct ast_xml_ns * ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name)
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
int ast_xml_doc_dump_file(FILE *output, struct ast_xml_doc *doc)
Dump the specified document to a file.
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
#define ast_debug(level,...)
Log a DEBUG message.
const char * ast_xml_node_get_name(struct ast_xml_node *node)
Get the name of a 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.
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_children(struct ast_xml_node *node)
Get the node's children.
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.
struct ast_xml_doc * ast_xml_get_doc(struct ast_xml_node *node)
Get the document based on a 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_node * ast_xml_xpath_get_first_result(struct ast_xml_xpath_results *results)
Return the first result node of an XPath query.
Support for logging to various files, console and syslog Configuration in file logger.conf.
struct ast_xml_node * ast_xml_new_node(const char *name)
Create a XML node.
struct ast_xml_doc * ast_xml_read_memory(char *buffer, size_t size)
Open an XML document that resides in memory.
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value)
Set an attribute to a node.
struct ast_xml_node * ast_xml_node_get_parent(struct ast_xml_node *node)
Get the parent of a specified node.
static char context[AST_MAX_CONTEXT]
struct ast_xml_node * ast_xml_add_child_list(struct ast_xml_node *parent, struct ast_xml_node *child)
Add a list of child nodes, to a specified parent node.
struct ast_xml_node * ast_xml_get_root(struct ast_xml_doc *doc)
Get the document root node.
struct ast_xml_doc * ast_xml_open(char *filename)
Open an XML document.
void ast_xml_free_node(struct ast_xml_node *node)
Free node.
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.