Commit 7869729c authored by Daniel Veillard's avatar Daniel Veillard
Browse files

adding xmlNodeBufGetContent() allowing to grab the content without forcing

* tree.c include/libxml/tree.h: adding xmlNodeBufGetContent()
  allowing to grab the content without forcing allocations.
* python/libxml2class.txt doc/libxml2-api.xml: rebuilt the API
* xpath.c xmldwalk.c: removed a couple of comment errors.
Daniel
parent a07050dd
Sun Oct 19 22:42:16 CEST 2003 Daniel Veillard <daniel@veillard.com>
* tree.c include/libxml/tree.h: adding xmlNodeBufGetContent()
allowing to grab the content without forcing allocations.
* python/libxml2class.txt doc/libxml2-api.xml: rebuilt the API
* xpath.c xmldwalk.c: removed a couple of comment errors.
Sun Oct 19 16:39:36 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
* parser.c: applied patch from Chris Anderson to change back
......
This diff is collapsed.
......@@ -927,6 +927,9 @@ XMLPUBFUN void XMLCALL
int len);
XMLPUBFUN xmlChar * XMLCALL
xmlNodeGetContent (xmlNodePtr cur);
XMLPUBFUN int XMLCALL
xmlNodeBufGetContent (xmlBufferPtr buffer,
xmlNodePtr cur);
XMLPUBFUN xmlChar * XMLCALL
xmlNodeGetLang (xmlNodePtr cur);
XMLPUBFUN int XMLCALL
......
......@@ -48,6 +48,16 @@ loadSGMLSuperCatalog()
newCatalog()
parseCatalogFile()
# functions from module chvalid
isBaseChar()
isBlank()
isChar()
isCombining()
isDigit()
isExtender()
isIdeographic()
isPubidChar()
# functions from module debugXML
boolToText()
debugDumpString()
......
......@@ -4707,6 +4707,148 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
return(oldbase);
}
/**
* xmlNodeBufGetContent:
* @buffer: a buffer
* @cur: the node being read
*
* Read the value of a node @cur, this can be either the text carried
* directly by this node if it's a TEXT node or the aggregate string
* of the values carried by this node child's (TEXT and ENTITY_REF).
* Entity references are substituted.
* Fills up the buffer @buffer with this value
*
* Returns 0 in case of success and -1 in case of error.
*/
int
xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
{
if ((cur == NULL) || (buffer == NULL)) return(-1);
switch (cur->type) {
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
xmlBufferCat(buffer, cur->content);
break;
case XML_DOCUMENT_FRAG_NODE:
case XML_ELEMENT_NODE:{
xmlNodePtr tmp = cur;
while (tmp != NULL) {
switch (tmp->type) {
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
if (tmp->content != NULL)
xmlBufferCat(buffer, tmp->content);
break;
case XML_ENTITY_REF_NODE:
xmlNodeBufGetContent(buffer, tmp->children);
break;
default:
break;
}
/*
* Skip to next node
*/
if (tmp->children != NULL) {
if (tmp->children->type != XML_ENTITY_DECL) {
tmp = tmp->children;
continue;
}
}
if (tmp == cur)
break;
if (tmp->next != NULL) {
tmp = tmp->next;
continue;
}
do {
tmp = tmp->parent;
if (tmp == NULL)
break;
if (tmp == cur) {
tmp = NULL;
break;
}
if (tmp->next != NULL) {
tmp = tmp->next;
break;
}
} while (tmp != NULL);
}
break;
}
case XML_ATTRIBUTE_NODE:{
xmlAttrPtr attr = (xmlAttrPtr) cur;
xmlNodePtr tmp = attr->children;
while (tmp != NULL) {
if (tmp->type == XML_TEXT_NODE)
xmlBufferCat(buffer, tmp->content);
else
xmlNodeBufGetContent(buffer, tmp);
tmp = tmp->next;
}
break;
}
case XML_COMMENT_NODE:
case XML_PI_NODE:
xmlBufferCat(buffer, cur->content);
break;
case XML_ENTITY_REF_NODE:{
xmlEntityPtr ent;
xmlNodePtr tmp;
/* lookup entity declaration */
ent = xmlGetDocEntity(cur->doc, cur->name);
if (ent == NULL)
return(-1);
/* an entity content can be any "well balanced chunk",
* i.e. the result of the content [43] production:
* http://www.w3.org/TR/REC-xml#NT-content
* -> we iterate through child nodes and recursive call
* xmlNodeGetContent() which handles all possible node types */
tmp = ent->children;
while (tmp) {
xmlNodeBufGetContent(buffer, tmp);
tmp = tmp->next;
}
break;
}
case XML_ENTITY_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
break;
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
cur = cur->children;
while (cur!= NULL) {
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE)) {
xmlNodeBufGetContent(buffer, cur);
}
cur = cur->next;
}
break;
case XML_NAMESPACE_DECL:
xmlBufferCat(buffer, ((xmlNsPtr) cur)->href);
break;
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
break;
}
return(0);
}
/**
* xmlNodeGetContent:
* @cur: the node being read
......
......@@ -621,7 +621,7 @@ xmlDocWalkerNamespaceUri(xmlDocWalkerPtr iter)
}
/**
* xmlTextReaderBaseUri:
* xmlDocWalkerBaseUri:
* @iter: the xmlDocWalkerPtr
*
* The base URI of the node.
......
......@@ -264,11 +264,7 @@ xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra)
/**
* xmlXPathErr:
* @ctxt: a XPath parser context
* @node: the node raising the error
* @error: the error code
* @msg: message
* @str1: extra info
* @str2: extra info
*
* Handle a Relax NG Parsing error
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment