Annotation of XML/debugXML.c, revision 1.10

1.1       daniel      1: /*
                      2:  * debugXML.c : This is a set of routines used for debugging the tree
                      3:  *              produced by the XML parser.
                      4:  *
1.2       daniel      5:  * See Copyright for the status of this software.
                      6:  *
1.1       daniel      7:  * Daniel Veillard <Daniel.Veillard@w3.org>
                      8:  */
                      9: 
                     10: #include <stdio.h>
                     11: #include "tree.h"
                     12: #include "parser.h"
                     13: #include "debugXML.h"
                     14: 
                     15: #define IS_BLANK(c)                                                    \
                     16:   (((c) == '\n') || ((c) == '\r') || ((c) == '\t') || ((c) == ' '))
                     17: 
1.6       daniel     18: void xmlDebugDumpString(FILE *output, const xmlChar *str) {
1.1       daniel     19:     int i;
                     20:     for (i = 0;i < 40;i++)
                     21:         if (str[i] == 0) return;
                     22:        else if (IS_BLANK(str[i])) fputc(' ', output);
                     23:        else fputc(str[i], output);
                     24:     fprintf(output, "...");
                     25: }
                     26: 
                     27: void xmlDebugDumpNamespace(FILE *output, xmlNsPtr ns, int depth) {
                     28:     int i;
                     29:     char shift[100];
                     30: 
                     31:     for (i = 0;((i < depth) && (i < 25));i++)
                     32:         shift[2 * i] = shift[2 * i + 1] = ' ';
                     33:     shift[2 * i] = shift[2 * i + 1] = 0;
                     34: 
                     35:     fprintf(output, shift);
                     36:     if (ns->type == XML_GLOBAL_NAMESPACE)
                     37:         fprintf(output, "old ");
1.10    ! daniel     38:     if (ns->prefix != NULL)
        !            39:        fprintf(output, "namespace %s href=", ns->prefix);
        !            40:     else
        !            41:        fprintf(output, "default namespace href=", ns->prefix);
        !            42: 
1.1       daniel     43:     xmlDebugDumpString(output, ns->href);
                     44:     fprintf(output, "\n");
                     45: }
                     46: 
                     47: void xmlDebugDumpNamespaceList(FILE *output, xmlNsPtr ns, int depth) {
                     48:     while (ns != NULL) {
                     49:         xmlDebugDumpNamespace(output, ns, depth);
                     50:        ns = ns->next;
                     51:     }
                     52: }
                     53: 
                     54: void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) {
                     55:     int i;
                     56:     char shift[100];
                     57: 
                     58:     for (i = 0;((i < depth) && (i < 25));i++)
                     59:         shift[2 * i] = shift[2 * i + 1] = ' ';
                     60:     shift[2 * i] = shift[2 * i + 1] = 0;
                     61: 
                     62:     fprintf(output, shift);
                     63:     switch (ent->type) {
                     64:         case XML_INTERNAL_GENERAL_ENTITY:
                     65:            fprintf(output, "INTERNAL_GENERAL_ENTITY ");
                     66:            break;
                     67:         case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
                     68:            fprintf(output, "EXTERNAL_GENERAL_PARSED_ENTITY ");
                     69:            break;
                     70:         case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
                     71:            fprintf(output, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");
                     72:            break;
                     73:         case XML_INTERNAL_PARAMETER_ENTITY:
                     74:            fprintf(output, "INTERNAL_PARAMETER_ENTITY ");
                     75:            break;
                     76:         case XML_EXTERNAL_PARAMETER_ENTITY:
                     77:            fprintf(output, "EXTERNAL_PARAMETER_ENTITY ");
                     78:            break;
                     79:        default:
                     80:            fprintf(output, "ENTITY_%d ! ", ent->type);
                     81:     }
                     82:     fprintf(output, "%s\n", ent->name);
                     83:     if (ent->ExternalID) {
                     84:         fprintf(output, shift);
                     85:         fprintf(output, "ExternalID=%s\n", ent->ExternalID);
                     86:     }
                     87:     if (ent->SystemID) {
                     88:         fprintf(output, shift);
                     89:         fprintf(output, "SystemID=%s\n", ent->SystemID);
                     90:     }
                     91:     if (ent->content) {
                     92:         fprintf(output, shift);
                     93:        fprintf(output, "content=");
                     94:        xmlDebugDumpString(output, ent->content);
                     95:        fprintf(output, "\n");
                     96:     }
                     97: }
                     98: 
                     99: void xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
                    100:     int i;
                    101:     char shift[100];
                    102: 
                    103:     for (i = 0;((i < depth) && (i < 25));i++)
                    104:         shift[2 * i] = shift[2 * i + 1] = ' ';
                    105:     shift[2 * i] = shift[2 * i + 1] = 0;
                    106: 
                    107:     fprintf(output, shift);
                    108:     fprintf(output, "ATTRIBUTE %s\n", attr->name);
                    109:     if (attr->val != NULL) 
                    110:         xmlDebugDumpNodeList(output, attr->val, depth + 1);
                    111: }
                    112: 
                    113: void xmlDebugDumpAttrList(FILE *output, xmlAttrPtr attr, int depth) {
                    114:     while (attr != NULL) {
                    115:         xmlDebugDumpAttr(output, attr, depth);
                    116:        attr = attr->next;
                    117:     }
                    118: }
                    119: 
1.3       daniel    120: void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) {
1.1       daniel    121:     int i;
                    122:     char shift[100];
                    123: 
                    124:     for (i = 0;((i < depth) && (i < 25));i++)
                    125:         shift[2 * i] = shift[2 * i + 1] = ' ';
                    126:     shift[2 * i] = shift[2 * i + 1] = 0;
                    127: 
                    128:     fprintf(output, shift);
                    129:     switch (node->type) {
                    130:        case XML_ELEMENT_NODE:
                    131:            fprintf(output, "ELEMENT ");
                    132:            if (node->ns != NULL)
                    133:                fprintf(output, "%s:%s\n", node->ns->prefix, node->name);
                    134:            else
                    135:                fprintf(output, "%s\n", node->name);
                    136:            break;
                    137:        case XML_ATTRIBUTE_NODE:
                    138:            fprintf(output, "Error, ATTRIBUTE found here\n");
                    139:            break;
                    140:        case XML_TEXT_NODE:
                    141:            fprintf(output, "TEXT\n");
                    142:            break;
                    143:        case XML_CDATA_SECTION_NODE:
                    144:            fprintf(output, "CDATA_SECTION\n");
                    145:            break;
                    146:        case XML_ENTITY_REF_NODE:
                    147:            fprintf(output, "ENTITY_REF\n");
                    148:            break;
                    149:        case XML_ENTITY_NODE:
                    150:            fprintf(output, "ENTITY\n");
                    151:            break;
                    152:        case XML_PI_NODE:
1.4       daniel    153:            fprintf(output, "PI %s\n", node->name);
1.1       daniel    154:            break;
                    155:        case XML_COMMENT_NODE:
                    156:            fprintf(output, "COMMENT\n");
                    157:            break;
                    158:        case XML_DOCUMENT_NODE:
1.7       daniel    159:        case XML_HTML_DOCUMENT_NODE:
1.1       daniel    160:            fprintf(output, "Error, DOCUMENT found here\n");
                    161:            break;
                    162:        case XML_DOCUMENT_TYPE_NODE:
                    163:            fprintf(output, "DOCUMENT_TYPE\n");
                    164:            break;
                    165:        case XML_DOCUMENT_FRAG_NODE:
                    166:            fprintf(output, "DOCUMENT_FRAG\n");
                    167:            break;
                    168:        case XML_NOTATION_NODE:
                    169:            fprintf(output, "NOTATION\n");
                    170:            break;
                    171:        default:
                    172:            fprintf(output, "NODE_%d\n", node->type);
                    173:     }
                    174:     if (node->doc == NULL) {
                    175:         fprintf(output, shift);
                    176:        fprintf(output, "doc == NULL !!!\n");
                    177:     }
                    178:     if (node->nsDef != NULL) 
                    179:         xmlDebugDumpNamespaceList(output, node->nsDef, depth + 1);
                    180:     if (node->properties != NULL)
                    181:        xmlDebugDumpAttrList(output, node->properties, depth + 1);
                    182:     if (node->type != XML_ENTITY_REF_NODE) {
                    183:        if (node->content != NULL) {
                    184:            fprintf(output, shift);
                    185:            fprintf(output, "content=");
1.8       daniel    186: #ifndef XML_USE_BUFFER_CONTENT     
1.1       daniel    187:            xmlDebugDumpString(output, node->content);
1.8       daniel    188: #else
                    189:            xmlDebugDumpString(output, xmlBufferContent(node->content));
                    190: #endif
1.1       daniel    191:            fprintf(output, "\n");
                    192:        }
                    193:     } else {
                    194:         xmlEntityPtr ent;
                    195:        ent = xmlGetDocEntity(node->doc, node->name);
                    196:        if (ent != NULL)
                    197:            xmlDebugDumpEntity(output, ent, depth + 1);
                    198:     }
1.3       daniel    199: }
                    200: 
                    201: void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) {
                    202:     xmlDebugDumpOneNode(output, node, depth);
1.1       daniel    203:     if (node->childs != NULL)
                    204:        xmlDebugDumpNodeList(output, node->childs, depth + 1);
                    205: }
                    206: 
                    207: void xmlDebugDumpNodeList(FILE *output, xmlNodePtr node, int depth) {
                    208:     while (node != NULL) {
                    209:         xmlDebugDumpNode(output, node, depth);
                    210:        node = node->next;
                    211:     }
                    212: }
                    213: 
                    214: 
                    215: void xmlDebugDumpDocument(FILE *output, xmlDocPtr doc) {
                    216:     if (output == NULL) output = stdout;
                    217:     if (doc == NULL) {
                    218:         fprintf(output, "DOCUMENT == NULL !\n");
                    219:        return;
                    220:     }
                    221: 
                    222:     switch (doc->type) {
                    223:        case XML_ELEMENT_NODE:
                    224:            fprintf(output, "Error, ELEMENT found here ");
                    225:            break;
                    226:        case XML_ATTRIBUTE_NODE:
                    227:            fprintf(output, "Error, ATTRIBUTE found here\n");
                    228:            break;
                    229:        case XML_TEXT_NODE:
                    230:            fprintf(output, "Error, TEXT\n");
                    231:            break;
                    232:        case XML_CDATA_SECTION_NODE:
                    233:            fprintf(output, "Error, CDATA_SECTION\n");
                    234:            break;
                    235:        case XML_ENTITY_REF_NODE:
                    236:            fprintf(output, "Error, ENTITY_REF\n");
                    237:            break;
                    238:        case XML_ENTITY_NODE:
                    239:            fprintf(output, "Error, ENTITY\n");
                    240:            break;
                    241:        case XML_PI_NODE:
                    242:            fprintf(output, "Error, PI\n");
                    243:            break;
                    244:        case XML_COMMENT_NODE:
                    245:            fprintf(output, "Error, COMMENT\n");
                    246:            break;
                    247:        case XML_DOCUMENT_NODE:
                    248:            fprintf(output, "DOCUMENT\n");
1.7       daniel    249:            break;
                    250:        case XML_HTML_DOCUMENT_NODE:
                    251:            fprintf(output, "HTML DOCUMENT\n");
1.1       daniel    252:            break;
                    253:        case XML_DOCUMENT_TYPE_NODE:
                    254:            fprintf(output, "Error, DOCUMENT_TYPE\n");
                    255:            break;
                    256:        case XML_DOCUMENT_FRAG_NODE:
                    257:            fprintf(output, "Error, DOCUMENT_FRAG\n");
                    258:            break;
                    259:        case XML_NOTATION_NODE:
                    260:            fprintf(output, "Error, NOTATION\n");
                    261:            break;
                    262:        default:
                    263:            fprintf(output, "NODE_%d\n", doc->type);
                    264:     }
                    265:     if (doc->name != NULL) {
                    266:        fprintf(output, "name=");
1.5       daniel    267:         xmlDebugDumpString(output, BAD_CAST doc->name);
1.1       daniel    268:        fprintf(output, "\n");
                    269:     }
                    270:     if (doc->version != NULL) {
                    271:        fprintf(output, "version=");
                    272:         xmlDebugDumpString(output, doc->version);
                    273:        fprintf(output, "\n");
                    274:     }
                    275:     if (doc->encoding != NULL) {
                    276:        fprintf(output, "encoding=");
                    277:         xmlDebugDumpString(output, doc->encoding);
                    278:        fprintf(output, "\n");
                    279:     }
                    280:     if (doc->standalone)
                    281:         fprintf(output, "standalone=true\n");
                    282:     if (doc->oldNs != NULL) 
                    283:         xmlDebugDumpNamespaceList(output, doc->oldNs, 0);
                    284:     if (doc->root != NULL)
                    285:         xmlDebugDumpNodeList(output, doc->root, 1);
                    286: }
1.9       daniel    287: 
                    288: void xmlDebugDumpEntities(FILE *output, xmlDocPtr doc) {
                    289:     int i;
                    290:     xmlEntityPtr cur;
                    291: 
                    292:     if (output == NULL) output = stdout;
                    293:     if (doc == NULL) {
                    294:         fprintf(output, "DOCUMENT == NULL !\n");
                    295:        return;
                    296:     }
                    297: 
                    298:     switch (doc->type) {
                    299:        case XML_ELEMENT_NODE:
                    300:            fprintf(output, "Error, ELEMENT found here ");
                    301:            break;
                    302:        case XML_ATTRIBUTE_NODE:
                    303:            fprintf(output, "Error, ATTRIBUTE found here\n");
                    304:            break;
                    305:        case XML_TEXT_NODE:
                    306:            fprintf(output, "Error, TEXT\n");
                    307:            break;
                    308:        case XML_CDATA_SECTION_NODE:
                    309:            fprintf(output, "Error, CDATA_SECTION\n");
                    310:            break;
                    311:        case XML_ENTITY_REF_NODE:
                    312:            fprintf(output, "Error, ENTITY_REF\n");
                    313:            break;
                    314:        case XML_ENTITY_NODE:
                    315:            fprintf(output, "Error, ENTITY\n");
                    316:            break;
                    317:        case XML_PI_NODE:
                    318:            fprintf(output, "Error, PI\n");
                    319:            break;
                    320:        case XML_COMMENT_NODE:
                    321:            fprintf(output, "Error, COMMENT\n");
                    322:            break;
                    323:        case XML_DOCUMENT_NODE:
                    324:            fprintf(output, "DOCUMENT\n");
                    325:            break;
                    326:        case XML_HTML_DOCUMENT_NODE:
                    327:            fprintf(output, "HTML DOCUMENT\n");
                    328:            break;
                    329:        case XML_DOCUMENT_TYPE_NODE:
                    330:            fprintf(output, "Error, DOCUMENT_TYPE\n");
                    331:            break;
                    332:        case XML_DOCUMENT_FRAG_NODE:
                    333:            fprintf(output, "Error, DOCUMENT_FRAG\n");
                    334:            break;
                    335:        case XML_NOTATION_NODE:
                    336:            fprintf(output, "Error, NOTATION\n");
                    337:            break;
                    338:        default:
                    339:            fprintf(output, "NODE_%d\n", doc->type);
                    340:     }
                    341:     if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
                    342:         xmlEntitiesTablePtr table = (xmlEntitiesTablePtr) 
                    343:                                    doc->intSubset->entities;
                    344:        fprintf(output, "Entities in internal subset\n");
                    345:        for (i = 0;i < table->nb_entities;i++) {
                    346:            cur = &table->table[i];
                    347:            fprintf(output, "%d : %s : ", i, cur->name);
                    348:            switch (cur->type) {
                    349:                case XML_INTERNAL_GENERAL_ENTITY:
                    350:                    fprintf(output, "INTERNAL GENERAL");
                    351:                    break;
                    352:                case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
                    353:                    fprintf(output, "EXTERNAL PARSED");
                    354:                    break;
                    355:                case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
                    356:                    fprintf(output, "EXTERNAL UNPARSED");
                    357:                    break;
                    358:                case XML_INTERNAL_PARAMETER_ENTITY:
                    359:                    fprintf(output, "INTERNAL PARAMETER");
                    360:                    break;
                    361:                case XML_EXTERNAL_PARAMETER_ENTITY:
                    362:                    fprintf(output, "EXTERNAL PARAMETER");
                    363:                    break;
                    364:                default:
                    365:                    fprintf(output, "UNKNOWN TYPE %d",
                    366:                            cur->type);
                    367:            }
                    368:            if (cur->ExternalID != NULL) 
                    369:                fprintf(output, "ID \"%s\"", cur->ExternalID);
                    370:            if (cur->SystemID != NULL)
                    371:                fprintf(output, "SYSTEM \"%s\"", cur->SystemID);
                    372:            if (cur->orig != NULL)
                    373:                fprintf(output, "\n orig \"%s\"", cur->orig);
                    374:            if (cur->content != NULL)
                    375:                fprintf(output, "\n content \"%s\"", cur->content);
                    376:            fprintf(output, "\n");      
                    377:        }
                    378:     } else
                    379:        fprintf(output, "No entities in internal subset\n");
                    380:     if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
                    381:         xmlEntitiesTablePtr table = (xmlEntitiesTablePtr) 
                    382:                                    doc->extSubset->entities;
                    383:        fprintf(output, "Entities in external subset\n");
                    384:        for (i = 0;i < table->nb_entities;i++) {
                    385:            cur = &table->table[i];
                    386:            fprintf(output, "%d : %s : ", i, cur->name);
                    387:            switch (cur->type) {
                    388:                case XML_INTERNAL_GENERAL_ENTITY:
                    389:                    fprintf(output, "INTERNAL GENERAL");
                    390:                    break;
                    391:                case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
                    392:                    fprintf(output, "EXTERNAL PARSED");
                    393:                    break;
                    394:                case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
                    395:                    fprintf(output, "EXTERNAL UNPARSED");
                    396:                    break;
                    397:                case XML_INTERNAL_PARAMETER_ENTITY:
                    398:                    fprintf(output, "INTERNAL PARAMETER");
                    399:                    break;
                    400:                case XML_EXTERNAL_PARAMETER_ENTITY:
                    401:                    fprintf(output, "EXTERNAL PARAMETER");
                    402:                    break;
                    403:                default:
                    404:                    fprintf(output, "UNKNOWN TYPE %d",
                    405:                            cur->type);
                    406:            }
                    407:            if (cur->ExternalID != NULL) 
                    408:                fprintf(output, "ID \"%s\"", cur->ExternalID);
                    409:            if (cur->SystemID != NULL)
                    410:                fprintf(output, "SYSTEM \"%s\"", cur->SystemID);
                    411:            if (cur->orig != NULL)
                    412:                fprintf(output, "\n orig \"%s\"", cur->orig);
                    413:            if (cur->content != NULL)
                    414:                fprintf(output, "\n content \"%s\"", cur->content);
                    415:            fprintf(output, "\n");      
                    416:        }
                    417:     } else
                    418:        fprintf(output, "No entities in external subset\n");
                    419: }

Webmaster