Skip to content

Commit

Permalink
440226 Add xmlXIncludeProcessTreeFlagsData API
Browse files Browse the repository at this point in the history
* xinclude.c include/libxml/xinclude.h: new function similar to
  xmlXIncludeProcessFlagsData but operating on a subtree
  • Loading branch information
scoder authored and veillard committed Aug 24, 2009
1 parent 56a0303 commit b9590e9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
14 changes: 9 additions & 5 deletions include/libxml/xinclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,22 @@ typedef xmlXIncludeCtxt *xmlXIncludeCtxtPtr;
/*
* standalone processing
*/
XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlXIncludeProcess (xmlDocPtr doc);
XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlXIncludeProcessFlags (xmlDocPtr doc,
int flags);
XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlXIncludeProcessFlagsData(xmlDocPtr doc,
int flags,
void *data);
XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlXIncludeProcessTreeFlagsData(xmlNodePtr tree,
int flags,
void *data);
XMLPUBFUN int XMLCALL
xmlXIncludeProcessTree (xmlNodePtr tree);
XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlXIncludeProcessTreeFlags(xmlNodePtr tree,
int flags);
/*
Expand Down
51 changes: 37 additions & 14 deletions xinclude.c
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,42 @@ xmlXIncludeSetFlags(xmlXIncludeCtxtPtr ctxt, int flags) {
ctxt->parseFlags = flags;
return(0);
}


/**
* xmlXIncludeProcessTreeFlagsData:
* @tree: an XML node
* @flags: a set of xmlParserOption used for parsing XML includes
* @data: application data that will be passed to the parser context
* in the _private field of the parser context(s)
*
* Implement the XInclude substitution on the XML node @tree
*
* Returns 0 if no substitution were done, -1 if some processing failed
* or the number of substitutions done.
*/

int
xmlXIncludeProcessTreeFlagsData(xmlNodePtr tree, int flags, void *data) {
xmlXIncludeCtxtPtr ctxt;
int ret = 0;

if ((tree == NULL) || (tree->doc == NULL))
return(-1);

ctxt = xmlXIncludeNewContext(tree->doc);
if (ctxt == NULL)
return(-1);
ctxt->_private = data;
ctxt->base = xmlStrdup((xmlChar *)tree->doc->URL);
xmlXIncludeSetFlags(ctxt, flags);
ret = xmlXIncludeDoProcess(ctxt, tree->doc, tree);
if ((ret >= 0) && (ctxt->nbErrors > 0))
ret = -1;

xmlXIncludeFreeContext(ctxt);
return(ret);
}

/**
* xmlXIncludeProcessFlagsData:
* @doc: an XML document
Expand All @@ -2440,25 +2475,13 @@ int
xmlXIncludeProcessFlagsData(xmlDocPtr doc, int flags, void *data) {
xmlXIncludeCtxtPtr ctxt;
xmlNodePtr tree;
int ret = 0;

if (doc == NULL)
return(-1);
tree = xmlDocGetRootElement(doc);
if (tree == NULL)
return(-1);
ctxt = xmlXIncludeNewContext(doc);
if (ctxt == NULL)
return(-1);
ctxt->_private = data;
ctxt->base = xmlStrdup((xmlChar *)doc->URL);
xmlXIncludeSetFlags(ctxt, flags);
ret = xmlXIncludeDoProcess(ctxt, doc, tree);
if ((ret >= 0) && (ctxt->nbErrors > 0))
ret = -1;

xmlXIncludeFreeContext(ctxt);
return(ret);
return(xmlXIncludeProcessTreeFlagsData(tree, flags, data));
}

/**
Expand Down

0 comments on commit b9590e9

Please sign in to comment.