Handling non-element data: charData

Previous: Handling elements: endElement ] [ Top: xmltools index ] [ Next: xmltools index ]

Handling character data (that's just text which is enclosed in an element but is not itself a tag) is pretty straightforward, as there is nothing to do with the stack. It still looks ugly due to all the #ifdef stuff, but hey. It works.

There are basically two things going on here. First, if our enclosing tag is still empty, then we close it (as long as we're emitting tags, and we're inside our snip location or we're not replacing the tag, same ol same ol on all that stuff.)

After that's done, we emit the character data, as long as we're supposed to be emitting character data (and pretty much with the same caveats for xmlsnip and xmlreplace.)
 
void charData (void *userData, const XML_Char *s, int len) {
   int i;
   /* If parent is still empty, close its tag. */
#ifdef XMLSNIP
   if (!finished && emit_level > -1 && top->level - 1 + emit_matching_tag >= emit_level && top->empty == 1) {
#else
#ifdef XMLREPLACE
   if ((emit_level < 0 || top->level < emit_level) && top->empty == 1) {
#else
   if (top->empty == 1) {
#endif
#endif
      printf (">");
      top->empty = 0;
   }

#ifdef XMLSNIP
   if (!finished && emit_level > -1 && top->level >= emit_level) {
#else
#ifdef XMLREPLACE
   if (emit_level < 0 || top->level < emit_level) {
#else
   if (1) {
#endif
#endif
      for (i=0; i < len; i++) {
         putchar (s[i]);
      }
   }
}
Previous: Handling elements: endElement ] [ Top: xmltools index ] [ Next: xmltools index ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.