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