cvs commit: ALFS/nALFS/src libXML-tree.c parser.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Fri Feb 13 20:32:22 PST 2004


kpfleming    04/02/13 21:32:22

  Modified:    nALFS/src libXML-tree.c parser.c
  Log:
  allow handlers to parse content if needed
  set element "parent" field early during parsing, in case handler needs it
  
  Revision  Changes    Path
  1.9       +29 -6     ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- libXML-tree.c	13 Feb 2004 07:08:59 -0000	1.8
  +++ libXML-tree.c	14 Feb 2004 04:32:22 -0000	1.9
  @@ -201,13 +201,34 @@
   			}
   		}
   
  -		result = handler->valid(element);
  +		/* If the handler cares about its content, pass it in
  +		   and check the result. */
  +
  +		if (handler->parse_content) {
  +			xmlChar *content;
  +
  +			if (node->children
  +			    && node->children->type == XML_TEXT_NODE
  +			    && node->children->next == NULL) {
  +				if ((content = xmlNodeGetContent(node))) {
  +					result = handler->parse_content(element,
  +									content);
  +					xfree(content);
  +					if (result)
  +						return result;
  +				}
  +			}
  +
  +		}
  +
  +		if (handler->valid)
  +			result = handler->valid(element);
   	}
   
   	return result;
   }
   
  -static INLINE element_s *create_element(xmlNodePtr node)
  +static INLINE element_s *create_element(xmlNodePtr node, element_s *parent)
   {
   	xmlChar *c;
   	handler_s *handler;
  @@ -215,6 +236,7 @@
   
   
   	el->id = element_id++;
  +	el->parent = parent;
   
   	switch (node->type) {
   		case XML_ELEMENT_NODE:
  @@ -273,7 +295,8 @@
   	return el;
   }
   
  -static element_s *convert_nodes(xmlNodePtr node, element_s *profile)
  +static element_s *convert_nodes(xmlNodePtr node, element_s *profile,
  +				element_s *parent)
   {
   	element_s *el, *c, *prev = NULL;
   	xmlNodePtr child;
  @@ -283,10 +306,10 @@
   		return NULL;
   	}
   
  -	el = create_element(node);
  +	el = create_element(node, parent);
   
   	for (child = node->children; child; child = child->next) {
  -		if ((c = convert_nodes(child, profile))) {
  +		if ((c = convert_nodes(child, profile, el))) {
   			link_element(c, prev, el, profile);
   
   			prev = c;
  @@ -318,7 +341,7 @@
   	profile->profile = profile;
   
   	for (child = doc->children; child; child = child->next) {
  -		if ((el = convert_nodes(child, profile))) {
  +		if ((el = convert_nodes(child, profile, profile))) {
   			link_element(el, prev, profile, profile);
   
   			prev = el;
  
  
  
  1.7       +1 -1      ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- parser.c	13 Feb 2004 04:26:41 -0000	1.6
  +++ parser.c	14 Feb 2004 04:32:22 -0000	1.7
  @@ -112,7 +112,7 @@
   {
   	/* Parent<->Child */
   	if (parent) {
  -		el->parent = parent;
  +		/* el->parent is set at parsing time */
   
   		if (parent->children == NULL) {
   			parent->children = el;
  
  
  



More information about the alfs-log mailing list