DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

Utilities for managing XML documents. More...

Modules

 XSLT Interface
 Utilities for managing XML documents.
 

Files

file  libxml2.c
 XML Interface.
 

Data Structures

struct  xml_attr
 XML attribute name value pair. More...
 
struct  xml_node
 Reference to a XML Node. More...
 
struct  xml_node_iter
 Iterator to traverse nodes in a xpath. More...
 
struct  xml_search
 XML xpath search result. More...
 

Typedefs

typedef struct xml_node xml_node
 Forward decleration of structure. More...
 
typedef struct xml_search xml_search
 Forward decleration of structure. More...
 
typedef struct xml_doc xml_doc
 Forward decleration of structure. More...
 

Functions

void xml_free_buffer (void *data)
 Reference destructor for xml_buffer. More...
 
struct xml_docxml_loaddoc (const char *docfile, int validate)
 Load a XML file into XML document and return reference. More...
 
struct xml_docxml_loadbuf (const uint8_t *buffer, uint32_t len, int validate)
 Load a buffer into XML document returning refereence. More...
 
struct xml_nodexml_getrootnode (struct xml_doc *xmldoc)
 Return reference to the root node. More...
 
struct xml_nodexml_getfirstnode (struct xml_search *xpsearch, void **iter)
 Return reference to the first node optionally creating a iterator. More...
 
struct xml_nodexml_getnextnode (void *iter)
 Return the next node. More...
 
struct bucket_listxml_getnodes (struct xml_search *xpsearch)
 Return reference to bucket list containing nodes. More...
 
struct xml_searchxml_xpath (struct xml_doc *xmldata, const char *xpath, const char *attrkey)
 Return a reference to a xpath search result. More...
 
int xml_nodecount (struct xml_search *xsearch)
 Return the number of nodes in the search path. More...
 
struct xml_nodexml_getnode (struct xml_search *xsearch, const char *key)
 Return a node in the search matching key. More...
 
const char * xml_getattr (struct xml_node *xnode, const char *attr)
 Return value of attribute. More...
 
const char * xml_getrootname (struct xml_doc *xmldoc)
 Return the name of the root node. More...
 
void xml_modify (struct xml_doc *xmldoc, struct xml_node *xnode, const char *value)
 Modify a XML node. More...
 
void xml_setattr (struct xml_doc *xmldoc, struct xml_node *xnode, const char *name, const char *value)
 Modify a XML node attribute. More...
 
void xml_createpath (struct xml_doc *xmldoc, const char *xpath)
 Create a path in XML document. More...
 
void xml_appendnode (struct xml_doc *xmldoc, const char *xpath, struct xml_node *child)
 Append a node to a path. More...
 
struct xml_nodexml_addnode (struct xml_doc *xmldoc, const char *xpath, const char *name, const char *value, const char *attrkey, const char *keyval)
 Append a node to a path. More...
 
void xml_unlink (struct xml_node *xnode)
 Unlink a node from the document. More...
 
void xml_delete (struct xml_node *xnode)
 Delete a node from document it is not unrefd and should be. More...
 
char * xml_getbuffer (void *buffer)
 Return the buffer of a xml_buffer structure. More...
 
void * xml_doctobuffer (struct xml_doc *xmldoc)
 Return a dump of a XML document. More...
 
void xml_init ()
 Initialise/Reference the XML library. More...
 
void xml_close ()
 Unreference the XML library. More...
 
void xml_savefile (struct xml_doc *xmldoc, const char *file, int format, int compress)
 Save XML document to a file. More...
 

Detailed Description

Utilities for managing XML documents.

Typedef Documentation

typedef struct xml_doc xml_doc

Forward decleration of structure.

Definition at line 631 of file dtsapp.h.

typedef struct xml_node xml_node

Forward decleration of structure.

Definition at line 625 of file dtsapp.h.

typedef struct xml_search xml_search

Forward decleration of structure.

Definition at line 628 of file dtsapp.h.

Function Documentation

struct xml_node* xml_addnode ( struct xml_doc xmldoc,
const char *  xpath,
const char *  name,
const char *  value,
const char *  attrkey,
const char *  keyval 
)

Append a node to a path.

Parameters
xmldocReference to XML document.
xpathPath to add the node too.
nameNode name.
valueNode value.
attrkeyAttribute to create on node.
keyvalAttribute value of attrkey.
Returns
reference to new node.

Definition at line 651 of file libxml2.c.

References objlock(), objref(), objunlock(), and objunref().

Referenced by xml_createpath().

652  {
653  struct xml_node *newnode;
654  xmlNodePtr parent;
655  xmlNodePtr child;
656  xmlChar *encval;
657 
658  if (!objref(xmldoc)) {
659  return NULL;
660  }
661 
662  objlock(xmldoc);
663  if (!(parent = xml_getparent(xmldoc, xpath))) {
664  objunlock(xmldoc);
665  objunref(xmldoc);
666  return NULL;
667  }
668 
669  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
670  child = xmlNewDocNode(xmldoc->doc, NULL, (const xmlChar *)name, encval);
671  xmlFree(encval);
672  xmlAddChild(parent,child);
673 
674  if (attrkey && keyval) {
675  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)keyval);
676  xmlSetProp(child, (const xmlChar *)attrkey, (const xmlChar *)encval);
677  xmlFree(encval);
678  }
679  objunlock(xmldoc);
680 
681  if (!(newnode = xml_nodetohash(xmldoc, child, attrkey))) {
682  objunref(xmldoc);
683  return NULL;
684  }
685 
686  objunref(xmldoc);
687 
688  return newnode;
689 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
const char * name
Name of the node.
Definition: dtsapp.h:650
const char * value
Value of the node.
Definition: dtsapp.h:652
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
Reference to a XML Node.
Definition: dtsapp.h:648
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xml_appendnode ( struct xml_doc xmldoc,
const char *  xpath,
struct xml_node child 
)

Append a node to a path.

Note
The child will most likely be a node unlinked and moved.
Parameters
xmldocReference to XML document.
xpathPath to add the node too.
childXML node to append to path.

Definition at line 625 of file libxml2.c.

References xml_node::nodeptr, objlock(), objref(), objunlock(), and objunref().

625  {
626  xmlNodePtr parent;
627 
628  if (!objref(xmldoc)) {
629  return;
630  }
631 
632  objlock(xmldoc);
633  if (!(parent = xml_getparent(xmldoc, xpath))) {
634  objunlock(xmldoc);
635  objunref(xmldoc);
636  }
637 
638  xmlAddChild(parent,child->nodeptr);
639  objunlock(xmldoc);
640  objunref(xmldoc);
641 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xml_close ( )

Unreference the XML library.

Ideally this should be done after a call to xml_init at shutdown.

Definition at line 758 of file libxml2.c.

References objunref().

758  {
759  if (xml_has_init_parser) {
760  objunref(xml_has_init_parser);
761  }
762 }
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xml_createpath ( struct xml_doc xmldoc,
const char *  xpath 
)

Create a path in XML document.

Note
xpath is not a full xpath just a path [no filters].
Parameters
xmldocReference to XML document.
xpathPath to create.

Definition at line 507 of file libxml2.c.

References xml_node::name, objlock(), objref(), objunlock(), objunref(), and xml_addnode().

507  {
508  struct xml_node *nn;
509  xmlXPathObjectPtr xpathObj;
510  char *lpath, *tok, *save, *cpath, *dup;
511  const char *root = (char *)xmldoc->root->name;
512  int len;
513 
514 
515  if (!objref(xmldoc)) {
516  return;
517  }
518 
519  if (!(dup = strdup(xpath))) {
520  objunref(xmldoc);
521  return;
522  }
523 
524  len = strlen(xpath)+1;
525  if (!(cpath = malloc(len))) {
526  free(dup);
527  objunref(xmldoc);
528  return;
529  }
530  if (!(lpath = malloc(len))) {
531  free(dup);
532  free(cpath);
533  objunref(xmldoc);
534  return;
535  }
536 
537  cpath[0] = '\0';
538  lpath[0] = '\0';
539 
540 #ifndef __WIN32__
541  for (tok = strtok_r(dup, "/", &save); tok ; tok = strtok_r(NULL, "/", &save)) {
542 #else
543  for (tok = strtok_s(dup, "/", &save); tok ; tok = strtok_s(NULL, "/", &save)) {
544 #endif
545  strcat(cpath,"/");
546  strcat(cpath, tok);
547  if (!strcmp(tok, root)) {
548  strcat(lpath,"/");
549  strcat(lpath, tok);
550  continue;
551  }
552 
553  objlock(xmldoc);
554  if (!(xpathObj = xmlXPathEvalExpression((const xmlChar *)cpath, xmldoc->xpathCtx))) {
555  objunlock(xmldoc);
556  free(lpath);
557  free(cpath);
558  free(dup);
559  objunref(xmldoc);
560  return;
561  }
562  objunlock(xmldoc);
563 
564  if (xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)) {
565  nn = xml_addnode(xmldoc, lpath, tok, NULL, NULL, NULL);
566  objunref(nn);
567  }
568 
569  xmlXPathFreeObject(xpathObj);
570  strcat(lpath,"/");
571  strcat(lpath, tok);
572  }
573 
574  free(dup);
575  free(lpath);
576  free(cpath);
577  objunref(xmldoc);
578 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
const char * name
Name of the node.
Definition: dtsapp.h:650
struct xml_node * xml_addnode(struct xml_doc *xmldoc, const char *xpath, const char *name, const char *value, const char *attrkey, const char *keyval)
Append a node to a path.
Definition: libxml2.c:651
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
Reference to a XML Node.
Definition: dtsapp.h:648
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xml_delete ( struct xml_node xnode)

Delete a node from document it is not unrefd and should be.

Parameters
xnodeReference to node to delete this must be unreferenced after calling this function.

Definition at line 701 of file libxml2.c.

References xml_node::nodeptr, objlock(), and objunlock().

701  {
702  objlock(xnode);
703  xmlUnlinkNode(xnode->nodeptr);
704  xmlFreeNode(xnode->nodeptr);
705  xnode->nodeptr = NULL;
706  objunlock(xnode);
707 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
void* xml_doctobuffer ( struct xml_doc xmldoc)

Return a dump of a XML document.

The result can be acessed using xml_getbuffer()

Parameters
xmldocReference to a XML document.
Returns
Reference to a xml_buffer structure.

Definition at line 726 of file libxml2.c.

References objalloc(), objlock(), objunlock(), and xml_free_buffer().

726  {
727  struct xml_buffer *xmlbuf;
728 
729  if (!(xmlbuf = objalloc(sizeof(*xmlbuf),xml_free_buffer))) {
730  return NULL;
731  }
732 
733  objlock(xmldoc);
734  xmlDocDumpFormatMemory(xmldoc->doc, &xmlbuf->buffer, &xmlbuf->size, 1);
735  objunlock(xmldoc);
736  return xmlbuf;
737 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
void xml_free_buffer(void *data)
Reference destructor for xml_buffer.
Definition: libxml2.c:46
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void xml_free_buffer ( void *  data)

Reference destructor for xml_buffer.

Warning
do not call this directly.

Definition at line 46 of file libxml2.c.

Referenced by xml_doctobuffer(), and xslt_apply_buffer().

46  {
47  struct xml_buffer *xb = data;
48  xmlFree(xb->buffer);
49 }
const char* xml_getattr ( struct xml_node xnode,
const char *  attr 
)

Return value of attribute.

Parameters
xnodeXML node reference.
attrAttribute to search for.
Returns
Value of the attribute valid while reference to node is held.

Definition at line 440 of file libxml2.c.

References xml_node::attrs, bucket_list_find_key(), objunref(), and xml_attr::value.

440  {
441  struct xml_attr *ainfo;
442 
443  if (!xnode) {
444  return NULL;
445  }
446 
447  if ((ainfo = bucket_list_find_key(xnode->attrs, attr))) {
448  objunref(ainfo);
449  return ainfo->value;
450  } else {
451  return NULL;
452  }
453 }
XML attribute name value pair.
Definition: dtsapp.h:639
struct bucket_list * attrs
Bucket list of attributes.
Definition: dtsapp.h:656
const char * value
Value of attribute.
Definition: dtsapp.h:643
void * bucket_list_find_key(struct bucket_list *list, const void *key)
Find and return a reference to a item matching supplied key.
Definition: refobj.c:572
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
char* xml_getbuffer ( void *  buffer)

Return the buffer of a xml_buffer structure.

Note
only valid while reference is held to the xml_buffer struct.
Parameters
bufferReference to a xml_buffer struct.

Definition at line 712 of file libxml2.c.

712  {
713  struct xml_buffer *xb = buffer;
714 
715  if (!xb) {
716  return NULL;
717  }
718  return (char *)xb->buffer;
719 }
struct xml_node* xml_getfirstnode ( struct xml_search xpsearch,
void **  iter 
)

Return reference to the first node optionally creating a iterator.

Setting the optional iterator and using it on future calls to xml_getnextnode its possible to iterate through the search path.

Todo:
Thread safety when XML doc changes.
Note
using xml_getnodes() returns a bucket list of nodes this is prefered.
Warning
This is not thread safe.
Parameters
xpsearchXML xpath search to find first node.
iterOptional iterator created and returned (must be unreferenced)
Returns
Reference to first node in the path.

Definition at line 295 of file libxml2.c.

References xml_node_iter::cnt, xml_node_iter::curpos, objalloc(), objlock(), objref(), objunlock(), objunref(), xml_nodecount(), and xml_node_iter::xsearch.

295  {
296  struct xml_node_iter *newiter;
297  struct xml_node *xn;
298 
299  if (!objref(xpsearch)) {
300  return NULL;
301  }
302 
303  if (iter) {
304  newiter = objalloc(sizeof(*newiter), free_iter);
305  objlock(xpsearch);
306  newiter->cnt = xml_nodecount(xpsearch);
307  objunlock(xpsearch);
308  newiter->curpos = 0;
309  newiter->xsearch = xpsearch;
310  objref(newiter->xsearch);
311  *iter = newiter;
312  }
313 
314  xn = xml_gethash(xpsearch, 0, NULL);
315  objunref(xpsearch);
316  return xn;
317 }
int curpos
current position.
Definition: libxml2.c:26
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int cnt
number of nodes in search path.
Definition: libxml2.c:28
Iterator to traverse nodes in a xpath.
Definition: libxml2.c:22
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
struct xml_search * xsearch
Reference to search returned from xml_search()
Definition: libxml2.c:24
int xml_nodecount(struct xml_search *xsearch)
Return the number of nodes in the search path.
Definition: libxml2.c:413
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
Reference to a XML Node.
Definition: dtsapp.h:648
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct xml_node* xml_getnextnode ( void *  iter)

Return the next node.

Parameters
iterIterator set in call to from xml_getfirstnode.
Returns
Reference to next node.

Definition at line 322 of file libxml2.c.

References xml_node_iter::cnt, xml_node_iter::curpos, objlock(), objref(), objunlock(), objunref(), and xml_node_iter::xsearch.

322  {
323  struct xml_node_iter *xi = iter;
324  struct xml_node *xn;
325 
326  if (!objref(xi->xsearch)) {
327  return NULL;
328  }
329 
330  objlock(xi);
331  xi->curpos ++;
332  if (xi->curpos >= xi->cnt) {
333  objunlock(xi);
334  objunref(xi->xsearch);
335  return NULL;
336  }
337  xn = xml_gethash(xi->xsearch, xi->curpos, NULL);
338  objunlock(xi);
339  objunref(xi->xsearch);
340 
341  return xn;
342 }
int curpos
current position.
Definition: libxml2.c:26
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int cnt
number of nodes in search path.
Definition: libxml2.c:28
Iterator to traverse nodes in a xpath.
Definition: libxml2.c:22
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
struct xml_search * xsearch
Reference to search returned from xml_search()
Definition: libxml2.c:24
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
Reference to a XML Node.
Definition: dtsapp.h:648
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct xml_node* xml_getnode ( struct xml_search xsearch,
const char *  key 
)

Return a node in the search matching key.

The key is matched against the index attribute supplied or the value of the node.

Parameters
xsearchReference to xpath search.
keyValue to use to find node matched aginst the index attribute/value.
Returns
Reference to XML node.

Definition at line 429 of file libxml2.c.

References bucket_list_find_key(), and xml_search::nodes.

429  {
430  if (!xsearch) {
431  return NULL;
432  }
433  return bucket_list_find_key(xsearch->nodes, key);
434 }
const char * key
Attribute key for searching and indexing.
Definition: dtsapp.h:654
struct bucket_list * nodes
Bucket list of all nodes.
Definition: libxml2.c:39
void * bucket_list_find_key(struct bucket_list *list, const void *key)
Find and return a reference to a item matching supplied key.
Definition: refobj.c:572
struct bucket_list* xml_getnodes ( struct xml_search xpsearch)

Return reference to bucket list containing nodes.

Note
use of this is prefered to xml_getfirstnode() / xml_getnextnode() if search order is not a issue.
Parameters
xpsearchReference to xpath search result returned by xml_xpath.
Returns
Reference to bucket list containing nodes.

Definition at line 349 of file libxml2.c.

References xml_search::nodes, and objref().

349  {
350  return (xpsearch && objref(xpsearch->nodes)) ? xpsearch->nodes : NULL;
351 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
struct bucket_list * nodes
Bucket list of all nodes.
Definition: libxml2.c:39
const char* xml_getrootname ( struct xml_doc xmldoc)

Return the name of the root node.

Note
do not free or unref this.
Parameters
xmldocXML Document.

Definition at line 458 of file libxml2.c.

458  {
459  if (xmldoc) {
460  return (const char *)xmldoc->root->name;
461  }
462  return NULL;
463 }
struct xml_node* xml_getrootnode ( struct xml_doc xmldoc)

Return reference to the root node.

Parameters
xmldocXML Document to find root in.

Definition at line 276 of file libxml2.c.

References objlock(), and objunlock().

276  {
277  struct xml_node *rn;
278 
279  objlock(xmldoc);
280  rn = xml_nodetohash(xmldoc, xmldoc->root, NULL);
281  objunlock(xmldoc);
282  return rn;
283 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
Reference to a XML Node.
Definition: dtsapp.h:648
void xml_init ( )

Initialise/Reference the XML library.

Ideally this should be done on application startup but will be started and stoped as needed.

Definition at line 742 of file libxml2.c.

References objalloc(), and objref().

Referenced by xml_loadbuf(), and xml_loaddoc().

742  {
743  if (!xml_has_init_parser) {
744  xml_has_init_parser = objalloc(0, free_parser);
745  xmlInitParser();
746  LIBXML_TEST_VERSION
747  xmlKeepBlanksDefault(0);
748  xmlLoadExtDtdDefaultValue = 1;
749  xmlSubstituteEntitiesDefault(1);
750  } else {
751  objref(xml_has_init_parser);
752  }
753 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
struct xml_doc* xml_loadbuf ( const uint8_t *  buffer,
uint32_t  len,
int  validate 
)

Load a buffer into XML document returning refereence.

Parameters
bufferBuffer containing the XML.
lenSize of the buffer.
validateSet to non zero value to fail if validation fails.
Returns
XML Document or NULL on failure

Definition at line 168 of file libxml2.c.

References objalloc(), objunref(), and xml_init().

Referenced by curl_buf2xml().

168  {
169  struct xml_doc *xmldata;
170  int flags;
171 
172  xml_init();
173 
174  if (!(xmldata = objalloc(sizeof(*xmldata), free_xmldata))) {
175  return NULL;
176  }
177 
178  if (validate) {
179  flags = XML_PARSE_DTDLOAD | XML_PARSE_DTDVALID;
180  } else {
181  flags = XML_PARSE_DTDVALID;
182  }
183 
184  if (!(xmldata->doc = xmlReadMemory((const char *)buffer, len, NULL, NULL, flags))) {
185  objunref(xmldata);
186  return NULL;
187  }
188  return xml_setup_parse(xmldata, 0);
189 }
struct xml_doc xml_doc
Forward decleration of structure.
Definition: dtsapp.h:631
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
void xml_init()
Initialise/Reference the XML library.
Definition: libxml2.c:742
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct xml_doc* xml_loaddoc ( const char *  docfile,
int  validate 
)

Load a XML file into XML document and return reference.

Parameters
docfilePathname to XML file.
validateSet to non zero value to fail if validation fails.
Returns
XML Document or NULL on failure

Definition at line 146 of file libxml2.c.

References objalloc(), objunref(), and xml_init().

146  {
147  struct xml_doc *xmldata;
148 
149  xml_init();
150 
151  if (!(xmldata = objalloc(sizeof(*xmldata), free_xmldata))) {
152  return NULL;
153  }
154 
155  if (!(xmldata->doc = xmlParseFile(docfile))) {
156  objunref(xmldata);
157  return NULL;
158  }
159 
160  return xml_setup_parse(xmldata, validate);
161 }
struct xml_doc xml_doc
Forward decleration of structure.
Definition: dtsapp.h:631
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
void xml_init()
Initialise/Reference the XML library.
Definition: libxml2.c:742
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xml_modify ( struct xml_doc xmldoc,
struct xml_node xnode,
const char *  value 
)

Modify a XML node.

Parameters
xmldocXML Document node belongs to
xnodeXML Node to modify.
valueValue to set.

Definition at line 469 of file libxml2.c.

References ALLOC_CONST, xml_node::nodeptr, objlock(), objunlock(), and xml_node::value.

469  {
470  xmlChar *encval;
471  xmlNodePtr node;
472 
473  objlock(xmldoc);
474  node = xnode->nodeptr;
475  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
476  xmlNodeSetContent(node, encval);
477  xmlFree(encval);
478  encval = xmlNodeListGetString(xmldoc->doc, node->xmlChildrenNode, 1);
479  objunlock(xmldoc);
480 
481  if (xnode->value) {
482  free((void*)xnode->value);
483  }
484  ALLOC_CONST(xnode->value, (const char *)encval);
485  xmlFree(encval);
486 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
const char * value
Value of the node.
Definition: dtsapp.h:652
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
Definition: dtsapp.h:959
int xml_nodecount ( struct xml_search xsearch)

Return the number of nodes in the search path.

Parameters
xsearchReference to XML xpath search (xml_xpath())
Returns
Number of of nodes.

Definition at line 413 of file libxml2.c.

References xml_search::xpathObj.

Referenced by xml_getfirstnode().

413  {
414  xmlNodeSetPtr nodeset;
415 
416  if (xsearch && xsearch->xpathObj && ((nodeset = xsearch->xpathObj->nodesetval))) {
417  return nodeset->nodeNr;
418  } else {
419  return 0;
420  }
421 }
xmlXPathObjectPtr xpathObj
Xpath object.
Definition: libxml2.c:37
void xml_savefile ( struct xml_doc xmldoc,
const char *  file,
int  format,
int  compress 
)

Save XML document to a file.

Parameters
xmldocReference to XML document to save.
fileFilename to write the XML document too.
formatFormating flag from libxml2.
compressCompression level 0[none]-9.

Definition at line 769 of file libxml2.c.

References objlock(), and objunlock().

769  {
770  objlock(xmldoc);
771  xmlSetDocCompressMode(xmldoc->doc, compress);
772  xmlSaveFormatFile(file, xmldoc->doc, format);
773  xmlSetDocCompressMode(xmldoc->doc, 0);
774  objunlock(xmldoc);
775 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void xml_setattr ( struct xml_doc xmldoc,
struct xml_node xnode,
const char *  name,
const char *  value 
)

Modify a XML node attribute.

Parameters
xmldocXML Document node belongs to
xnodeXML Node to modify.
nameAttribute to modify.
valueValue to set.

Definition at line 493 of file libxml2.c.

References xml_node::nodeptr, objlock(), and objunlock().

493  {
494  xmlChar *encval;
495 
496  objlock(xmldoc);
497  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
498  xmlSetProp(xnode->nodeptr, (const xmlChar *)name, (const xmlChar *)encval);
499  objunlock(xmldoc);
500  xmlFree(encval);
501 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
void xml_unlink ( struct xml_node xnode)

Unlink a node from the document.

Parameters
xnodeReference of node to unlink.

Definition at line 693 of file libxml2.c.

References xml_node::nodeptr, objlock(), and objunlock().

693  {
694  objlock(xnode);
695  xmlUnlinkNode(xnode->nodeptr);
696  objunlock(xnode);
697 }
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
struct xml_search* xml_xpath ( struct xml_doc xmldata,
const char *  xpath,
const char *  attrkey 
)

Return a reference to a xpath search result.

Parameters
xmldataXML Document to search.
xpathXpath search to apply.
attrkeyAttribute to index by.
Returns
Reference to XML search result.

Definition at line 381 of file libxml2.c.

References xml_search::nodes, objalloc(), objlock(), objref(), objunlock(), objunref(), xml_search::xmldoc, and xml_search::xpathObj.

381  {
382  struct xml_search *xpsearch;
383 
384  if (!objref(xmldata) || !(xpsearch = objalloc(sizeof(*xpsearch), free_xmlsearch))) {
385  return NULL;
386  }
387 
388  objlock(xmldata);
389  xpsearch->xmldoc = xmldata;
390  if (!(xpsearch->xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath, xmldata->xpathCtx))) {
391  objunlock(xmldata);
392  objunref(xpsearch);
393  return NULL;
394  }
395 
396  if (xmlXPathNodeSetIsEmpty(xpsearch->xpathObj->nodesetval)) {
397  objunlock(xmldata);
398  objunref(xpsearch);
399  return NULL;
400  }
401  objunlock(xmldata);
402 
403  if (!(xpsearch->nodes = xml_setnodes(xpsearch, attrkey))) {
404  objunref(xpsearch);
405  return NULL;
406  }
407  return xpsearch;
408 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
XML xpath search result.
Definition: libxml2.c:33
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
struct xml_doc * xmldoc
Reference to XML document.
Definition: libxml2.c:35
struct bucket_list * nodes
Bucket list of all nodes.
Definition: libxml2.c:39
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
xmlXPathObjectPtr xpathObj
Xpath object.
Definition: libxml2.c:37
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184