Tag
Hash :
39a1f9a3
Author :
Date :
1999-01-17T19:11:59
Speed, conformance testing, more parsing, general improvements, Daniel.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
/*
* debugXML.c : This is a set of routines used for debugging the tree
* produced by the XML parser.
*
* See Copyright for the status of this software.
*
* Daniel Veillard <Daniel.Veillard@w3.org>
*/
#include <stdio.h>
#include "tree.h"
#include "parser.h"
#include "debugXML.h"
#define IS_BLANK(c) \
(((c) == '\n') || ((c) == '\r') || ((c) == '\t') || ((c) == ' '))
void xmlDebugDumpString(FILE *output, const CHAR *str) {
int i;
for (i = 0;i < 40;i++)
if (str[i] == 0) return;
else if (IS_BLANK(str[i])) fputc(' ', output);
else fputc(str[i], output);
fprintf(output, "...");
}
void xmlDebugDumpNamespace(FILE *output, xmlNsPtr ns, int depth) {
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0;
fprintf(output, shift);
if (ns->type == XML_GLOBAL_NAMESPACE)
fprintf(output, "old ");
fprintf(output, "namespace %s href=", ns->prefix);
xmlDebugDumpString(output, ns->href);
fprintf(output, "\n");
}
void xmlDebugDumpNamespaceList(FILE *output, xmlNsPtr ns, int depth) {
while (ns != NULL) {
xmlDebugDumpNamespace(output, ns, depth);
ns = ns->next;
}
}
void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) {
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0;
fprintf(output, shift);
switch (ent->type) {
case XML_INTERNAL_GENERAL_ENTITY:
fprintf(output, "INTERNAL_GENERAL_ENTITY ");
break;
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
fprintf(output, "EXTERNAL_GENERAL_PARSED_ENTITY ");
break;
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
fprintf(output, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");
break;
case XML_INTERNAL_PARAMETER_ENTITY:
fprintf(output, "INTERNAL_PARAMETER_ENTITY ");
break;
case XML_EXTERNAL_PARAMETER_ENTITY:
fprintf(output, "EXTERNAL_PARAMETER_ENTITY ");
break;
default:
fprintf(output, "ENTITY_%d ! ", ent->type);
}
fprintf(output, "%s\n", ent->name);
if (ent->ExternalID) {
fprintf(output, shift);
fprintf(output, "ExternalID=%s\n", ent->ExternalID);
}
if (ent->SystemID) {
fprintf(output, shift);
fprintf(output, "SystemID=%s\n", ent->SystemID);
}
if (ent->content) {
fprintf(output, shift);
fprintf(output, "content=");
xmlDebugDumpString(output, ent->content);
fprintf(output, "\n");
}
}
void xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0;
fprintf(output, shift);
fprintf(output, "ATTRIBUTE %s\n", attr->name);
if (attr->val != NULL)
xmlDebugDumpNodeList(output, attr->val, depth + 1);
}
void xmlDebugDumpAttrList(FILE *output, xmlAttrPtr attr, int depth) {
while (attr != NULL) {
xmlDebugDumpAttr(output, attr, depth);
attr = attr->next;
}
}
void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) {
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0;
fprintf(output, shift);
switch (node->type) {
case XML_ELEMENT_NODE:
fprintf(output, "ELEMENT ");
if (node->ns != NULL)
fprintf(output, "%s:%s\n", node->ns->prefix, node->name);
else
fprintf(output, "%s\n", node->name);
break;
case XML_ATTRIBUTE_NODE:
fprintf(output, "Error, ATTRIBUTE found here\n");
break;
case XML_TEXT_NODE:
fprintf(output, "TEXT\n");
break;
case XML_CDATA_SECTION_NODE:
fprintf(output, "CDATA_SECTION\n");
break;
case XML_ENTITY_REF_NODE:
fprintf(output, "ENTITY_REF\n");
break;
case XML_ENTITY_NODE:
fprintf(output, "ENTITY\n");
break;
case XML_PI_NODE:
fprintf(output, "PI\n");
break;
case XML_COMMENT_NODE:
fprintf(output, "COMMENT\n");
break;
case XML_DOCUMENT_NODE:
fprintf(output, "Error, DOCUMENT found here\n");
break;
case XML_DOCUMENT_TYPE_NODE:
fprintf(output, "DOCUMENT_TYPE\n");
break;
case XML_DOCUMENT_FRAG_NODE:
fprintf(output, "DOCUMENT_FRAG\n");
break;
case XML_NOTATION_NODE:
fprintf(output, "NOTATION\n");
break;
default:
fprintf(output, "NODE_%d\n", node->type);
}
if (node->doc == NULL) {
fprintf(output, shift);
fprintf(output, "doc == NULL !!!\n");
}
if (node->nsDef != NULL)
xmlDebugDumpNamespaceList(output, node->nsDef, depth + 1);
if (node->properties != NULL)
xmlDebugDumpAttrList(output, node->properties, depth + 1);
if (node->type != XML_ENTITY_REF_NODE) {
if (node->content != NULL) {
fprintf(output, shift);
fprintf(output, "content=");
xmlDebugDumpString(output, node->content);
fprintf(output, "\n");
}
} else {
xmlEntityPtr ent;
ent = xmlGetDocEntity(node->doc, node->name);
if (ent != NULL)
xmlDebugDumpEntity(output, ent, depth + 1);
}
if (node->childs != NULL)
xmlDebugDumpNodeList(output, node->childs, depth + 1);
}
void xmlDebugDumpNodeList(FILE *output, xmlNodePtr node, int depth) {
while (node != NULL) {
xmlDebugDumpNode(output, node, depth);
node = node->next;
}
}
void xmlDebugDumpDocument(FILE *output, xmlDocPtr doc) {
if (output == NULL) output = stdout;
if (doc == NULL) {
fprintf(output, "DOCUMENT == NULL !\n");
return;
}
switch (doc->type) {
case XML_ELEMENT_NODE:
fprintf(output, "Error, ELEMENT found here ");
break;
case XML_ATTRIBUTE_NODE:
fprintf(output, "Error, ATTRIBUTE found here\n");
break;
case XML_TEXT_NODE:
fprintf(output, "Error, TEXT\n");
break;
case XML_CDATA_SECTION_NODE:
fprintf(output, "Error, CDATA_SECTION\n");
break;
case XML_ENTITY_REF_NODE:
fprintf(output, "Error, ENTITY_REF\n");
break;
case XML_ENTITY_NODE:
fprintf(output, "Error, ENTITY\n");
break;
case XML_PI_NODE:
fprintf(output, "Error, PI\n");
break;
case XML_COMMENT_NODE:
fprintf(output, "Error, COMMENT\n");
break;
case XML_DOCUMENT_NODE:
fprintf(output, "DOCUMENT\n");
break;
case XML_DOCUMENT_TYPE_NODE:
fprintf(output, "Error, DOCUMENT_TYPE\n");
break;
case XML_DOCUMENT_FRAG_NODE:
fprintf(output, "Error, DOCUMENT_FRAG\n");
break;
case XML_NOTATION_NODE:
fprintf(output, "Error, NOTATION\n");
break;
default:
fprintf(output, "NODE_%d\n", doc->type);
}
if (doc->name != NULL) {
fprintf(output, "name=");
xmlDebugDumpString(output, doc->name);
fprintf(output, "\n");
}
if (doc->version != NULL) {
fprintf(output, "version=");
xmlDebugDumpString(output, doc->version);
fprintf(output, "\n");
}
if (doc->encoding != NULL) {
fprintf(output, "encoding=");
xmlDebugDumpString(output, doc->encoding);
fprintf(output, "\n");
}
if (doc->standalone)
fprintf(output, "standalone=true\n");
if (doc->oldNs != NULL)
xmlDebugDumpNamespaceList(output, doc->oldNs, 0);
if (doc->root != NULL)
xmlDebugDumpNodeList(output, doc->root, 1);
}