Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * debugXML.c : This is a set of routines used for debugging the tree |
| 3 | * produced by the XML parser. |
| 4 | * |
| 5 | * See Copyright for the status of this software. |
| 6 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 7 | * Daniel Veillard <daniel@veillard.com> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 10 | #include "libxml.h" |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11 | #ifdef LIBXML_DEBUG_ENABLED |
| 12 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 13 | #include <string.h> |
| 14 | #ifdef HAVE_STDLIB_H |
| 15 | #include <stdlib.h> |
| 16 | #endif |
| 17 | #ifdef HAVE_STRING_H |
| 18 | #include <string.h> |
| 19 | #endif |
| 20 | #include <libxml/xmlmemory.h> |
| 21 | #include <libxml/tree.h> |
| 22 | #include <libxml/parser.h> |
Daniel Veillard | 567e1b4 | 2001-08-01 15:53:47 +0000 | [diff] [blame] | 23 | #include <libxml/parserInternals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 24 | #include <libxml/valid.h> |
| 25 | #include <libxml/debugXML.h> |
| 26 | #include <libxml/HTMLtree.h> |
| 27 | #include <libxml/HTMLparser.h> |
| 28 | #include <libxml/xmlerror.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 29 | #include <libxml/globals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 30 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 31 | /** |
| 32 | * xmlDebugDumpString: |
| 33 | * @output: the FILE * for the output |
| 34 | * @str: the string |
| 35 | * |
| 36 | * Dumps informations about the string, shorten it if necessary |
| 37 | */ |
| 38 | void |
| 39 | xmlDebugDumpString(FILE * output, const xmlChar * str) |
| 40 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 41 | int i; |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 42 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 43 | if (str == NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 44 | fprintf(output, "(NULL)"); |
| 45 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 46 | } |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 47 | for (i = 0; i < 40; i++) |
| 48 | if (str[i] == 0) |
| 49 | return; |
| 50 | else if (IS_BLANK(str[i])) |
| 51 | fputc(' ', output); |
| 52 | else if (str[i] >= 0x80) |
| 53 | fprintf(output, "#%X", str[i]); |
| 54 | else |
| 55 | fputc(str[i], output); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 56 | fprintf(output, "..."); |
| 57 | } |
| 58 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 59 | static void |
| 60 | xmlDebugDumpDtdNode(FILE *output, xmlDtdPtr dtd, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 61 | int i; |
| 62 | char shift[100]; |
| 63 | |
| 64 | for (i = 0;((i < depth) && (i < 25));i++) |
| 65 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 66 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 67 | |
| 68 | fprintf(output, shift); |
| 69 | |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 70 | if (dtd == NULL) { |
| 71 | fprintf(output, "DTD node is NULL\n"); |
| 72 | return; |
| 73 | } |
| 74 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 75 | if (dtd->type != XML_DTD_NODE) { |
| 76 | fprintf(output, "PBM: not a DTD\n"); |
| 77 | return; |
| 78 | } |
| 79 | if (dtd->name != NULL) |
| 80 | fprintf(output, "DTD(%s)", dtd->name); |
| 81 | else |
| 82 | fprintf(output, "DTD"); |
| 83 | if (dtd->ExternalID != NULL) |
| 84 | fprintf(output, ", PUBLIC %s", dtd->ExternalID); |
| 85 | if (dtd->SystemID != NULL) |
| 86 | fprintf(output, ", SYSTEM %s", dtd->SystemID); |
| 87 | fprintf(output, "\n"); |
| 88 | /* |
| 89 | * Do a bit of checking |
| 90 | */ |
| 91 | if (dtd->parent == NULL) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 92 | fprintf(output, "PBM: DTD has no parent\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 93 | if (dtd->doc == NULL) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 94 | fprintf(output, "PBM: DTD has no doc\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 95 | if ((dtd->parent != NULL) && (dtd->doc != dtd->parent->doc)) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 96 | fprintf(output, "PBM: DTD doc differs from parent's one\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 97 | if (dtd->prev == NULL) { |
| 98 | if ((dtd->parent != NULL) && (dtd->parent->children != (xmlNodePtr)dtd)) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 99 | fprintf(output, "PBM: DTD has no prev and not first of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 100 | } else { |
| 101 | if (dtd->prev->next != (xmlNodePtr) dtd) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 102 | fprintf(output, "PBM: DTD prev->next : back link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 103 | } |
| 104 | if (dtd->next == NULL) { |
| 105 | if ((dtd->parent != NULL) && (dtd->parent->last != (xmlNodePtr) dtd)) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 106 | fprintf(output, "PBM: DTD has no next and not last of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 107 | } else { |
| 108 | if (dtd->next->prev != (xmlNodePtr) dtd) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 109 | fprintf(output, "PBM: DTD next->prev : forward link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 113 | static void |
| 114 | xmlDebugDumpAttrDecl(FILE *output, xmlAttributePtr attr, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 115 | int i; |
| 116 | char shift[100]; |
| 117 | |
| 118 | for (i = 0;((i < depth) && (i < 25));i++) |
| 119 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 120 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 121 | |
| 122 | fprintf(output, shift); |
| 123 | |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 124 | if (attr == NULL) { |
| 125 | fprintf(output, "Attribute declaration is NULL\n"); |
| 126 | return; |
| 127 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 128 | if (attr->type != XML_ATTRIBUTE_DECL) { |
| 129 | fprintf(output, "PBM: not a Attr\n"); |
| 130 | return; |
| 131 | } |
| 132 | if (attr->name != NULL) |
| 133 | fprintf(output, "ATTRDECL(%s)", attr->name); |
| 134 | else |
| 135 | fprintf(output, "PBM ATTRDECL noname!!!"); |
| 136 | if (attr->elem != NULL) |
| 137 | fprintf(output, " for %s", attr->elem); |
| 138 | else |
| 139 | fprintf(output, " PBM noelem!!!"); |
| 140 | switch (attr->atype) { |
| 141 | case XML_ATTRIBUTE_CDATA: |
| 142 | fprintf(output, " CDATA"); |
| 143 | break; |
| 144 | case XML_ATTRIBUTE_ID: |
| 145 | fprintf(output, " ID"); |
| 146 | break; |
| 147 | case XML_ATTRIBUTE_IDREF: |
| 148 | fprintf(output, " IDREF"); |
| 149 | break; |
| 150 | case XML_ATTRIBUTE_IDREFS: |
| 151 | fprintf(output, " IDREFS"); |
| 152 | break; |
| 153 | case XML_ATTRIBUTE_ENTITY: |
| 154 | fprintf(output, " ENTITY"); |
| 155 | break; |
| 156 | case XML_ATTRIBUTE_ENTITIES: |
| 157 | fprintf(output, " ENTITIES"); |
| 158 | break; |
| 159 | case XML_ATTRIBUTE_NMTOKEN: |
| 160 | fprintf(output, " NMTOKEN"); |
| 161 | break; |
| 162 | case XML_ATTRIBUTE_NMTOKENS: |
| 163 | fprintf(output, " NMTOKENS"); |
| 164 | break; |
| 165 | case XML_ATTRIBUTE_ENUMERATION: |
| 166 | fprintf(output, " ENUMERATION"); |
| 167 | break; |
| 168 | case XML_ATTRIBUTE_NOTATION: |
| 169 | fprintf(output, " NOTATION "); |
| 170 | break; |
| 171 | } |
| 172 | if (attr->tree != NULL) { |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 173 | int indx; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 174 | xmlEnumerationPtr cur = attr->tree; |
| 175 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 176 | for (indx = 0;indx < 5; indx++) { |
| 177 | if (indx != 0) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 178 | fprintf(output, "|%s", cur->name); |
| 179 | else |
| 180 | fprintf(output, " (%s", cur->name); |
| 181 | cur = cur->next; |
| 182 | if (cur == NULL) break; |
| 183 | } |
| 184 | if (cur == NULL) |
| 185 | fprintf(output, ")"); |
| 186 | else |
| 187 | fprintf(output, "...)"); |
| 188 | } |
| 189 | switch (attr->def) { |
| 190 | case XML_ATTRIBUTE_NONE: |
| 191 | break; |
| 192 | case XML_ATTRIBUTE_REQUIRED: |
| 193 | fprintf(output, " REQUIRED"); |
| 194 | break; |
| 195 | case XML_ATTRIBUTE_IMPLIED: |
| 196 | fprintf(output, " IMPLIED"); |
| 197 | break; |
| 198 | case XML_ATTRIBUTE_FIXED: |
| 199 | fprintf(output, " FIXED"); |
| 200 | break; |
| 201 | } |
| 202 | if (attr->defaultValue != NULL) { |
| 203 | fprintf(output, "\""); |
| 204 | xmlDebugDumpString(output, attr->defaultValue); |
| 205 | fprintf(output, "\""); |
| 206 | } |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 207 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Do a bit of checking |
| 211 | */ |
| 212 | if (attr->parent == NULL) |
| 213 | fprintf(output, "PBM: Attr has no parent\n"); |
| 214 | if (attr->doc == NULL) |
| 215 | fprintf(output, "PBM: Attr has no doc\n"); |
| 216 | if ((attr->parent != NULL) && (attr->doc != attr->parent->doc)) |
| 217 | fprintf(output, "PBM: Attr doc differs from parent's one\n"); |
| 218 | if (attr->prev == NULL) { |
| 219 | if ((attr->parent != NULL) && (attr->parent->children != (xmlNodePtr)attr)) |
| 220 | fprintf(output, "PBM: Attr has no prev and not first of list\n"); |
| 221 | } else { |
| 222 | if (attr->prev->next != (xmlNodePtr) attr) |
| 223 | fprintf(output, "PBM: Attr prev->next : back link wrong\n"); |
| 224 | } |
| 225 | if (attr->next == NULL) { |
| 226 | if ((attr->parent != NULL) && (attr->parent->last != (xmlNodePtr) attr)) |
| 227 | fprintf(output, "PBM: Attr has no next and not last of list\n"); |
| 228 | } else { |
| 229 | if (attr->next->prev != (xmlNodePtr) attr) |
| 230 | fprintf(output, "PBM: Attr next->prev : forward link wrong\n"); |
| 231 | } |
| 232 | } |
| 233 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 234 | static void |
| 235 | xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 236 | int i; |
| 237 | char shift[100]; |
| 238 | |
| 239 | for (i = 0;((i < depth) && (i < 25));i++) |
| 240 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 241 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 242 | |
| 243 | fprintf(output, shift); |
| 244 | |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 245 | if (elem == NULL) { |
| 246 | fprintf(output, "Element declaration is NULL\n"); |
| 247 | return; |
| 248 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 249 | if (elem->type != XML_ELEMENT_DECL) { |
| 250 | fprintf(output, "PBM: not a Elem\n"); |
| 251 | return; |
| 252 | } |
| 253 | if (elem->name != NULL) { |
| 254 | fprintf(output, "ELEMDECL("); |
| 255 | xmlDebugDumpString(output, elem->name); |
| 256 | fprintf(output, ")"); |
| 257 | } else |
| 258 | fprintf(output, "PBM ELEMDECL noname!!!"); |
| 259 | switch (elem->etype) { |
Daniel Veillard | a10efa8 | 2001-04-18 13:09:01 +0000 | [diff] [blame] | 260 | case XML_ELEMENT_TYPE_UNDEFINED: |
| 261 | fprintf(output, ", UNDEFINED"); |
| 262 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 263 | case XML_ELEMENT_TYPE_EMPTY: |
| 264 | fprintf(output, ", EMPTY"); |
| 265 | break; |
| 266 | case XML_ELEMENT_TYPE_ANY: |
| 267 | fprintf(output, ", ANY"); |
| 268 | break; |
| 269 | case XML_ELEMENT_TYPE_MIXED: |
| 270 | fprintf(output, ", MIXED "); |
| 271 | break; |
| 272 | case XML_ELEMENT_TYPE_ELEMENT: |
| 273 | fprintf(output, ", MIXED "); |
| 274 | break; |
| 275 | } |
Daniel Veillard | 7db3773 | 2001-07-12 01:20:08 +0000 | [diff] [blame] | 276 | if ((elem->type != XML_ELEMENT_NODE) && |
| 277 | (elem->content != NULL)) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 278 | char buf[5001]; |
| 279 | |
| 280 | buf[0] = 0; |
Daniel Veillard | d3d0672 | 2001-08-15 12:06:36 +0000 | [diff] [blame] | 281 | xmlSnprintfElementContent(buf, 5000, elem->content, 1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 282 | buf[5000] = 0; |
| 283 | fprintf(output, "%s", buf); |
| 284 | } |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 285 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 286 | |
| 287 | /* |
| 288 | * Do a bit of checking |
| 289 | */ |
| 290 | if (elem->parent == NULL) |
| 291 | fprintf(output, "PBM: Elem has no parent\n"); |
| 292 | if (elem->doc == NULL) |
| 293 | fprintf(output, "PBM: Elem has no doc\n"); |
| 294 | if ((elem->parent != NULL) && (elem->doc != elem->parent->doc)) |
| 295 | fprintf(output, "PBM: Elem doc differs from parent's one\n"); |
| 296 | if (elem->prev == NULL) { |
| 297 | if ((elem->parent != NULL) && (elem->parent->children != (xmlNodePtr)elem)) |
| 298 | fprintf(output, "PBM: Elem has no prev and not first of list\n"); |
| 299 | } else { |
| 300 | if (elem->prev->next != (xmlNodePtr) elem) |
| 301 | fprintf(output, "PBM: Elem prev->next : back link wrong\n"); |
| 302 | } |
| 303 | if (elem->next == NULL) { |
| 304 | if ((elem->parent != NULL) && (elem->parent->last != (xmlNodePtr) elem)) |
| 305 | fprintf(output, "PBM: Elem has no next and not last of list\n"); |
| 306 | } else { |
| 307 | if (elem->next->prev != (xmlNodePtr) elem) |
| 308 | fprintf(output, "PBM: Elem next->prev : forward link wrong\n"); |
| 309 | } |
| 310 | } |
| 311 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 312 | static void |
| 313 | xmlDebugDumpEntityDecl(FILE *output, xmlEntityPtr ent, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 314 | int i; |
| 315 | char shift[100]; |
| 316 | |
| 317 | for (i = 0;((i < depth) && (i < 25));i++) |
| 318 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 319 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 320 | |
| 321 | fprintf(output, shift); |
| 322 | |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 323 | if (ent == NULL) { |
| 324 | fprintf(output, "Entity declaration is NULL\n"); |
| 325 | return; |
| 326 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 327 | if (ent->type != XML_ENTITY_DECL) { |
| 328 | fprintf(output, "PBM: not a Entity decl\n"); |
| 329 | return; |
| 330 | } |
| 331 | if (ent->name != NULL) { |
| 332 | fprintf(output, "ENTITYDECL("); |
| 333 | xmlDebugDumpString(output, ent->name); |
| 334 | fprintf(output, ")"); |
| 335 | } else |
| 336 | fprintf(output, "PBM ENTITYDECL noname!!!"); |
| 337 | switch (ent->etype) { |
| 338 | case XML_INTERNAL_GENERAL_ENTITY: |
| 339 | fprintf(output, ", internal\n"); |
| 340 | break; |
| 341 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 342 | fprintf(output, ", external parsed\n"); |
| 343 | break; |
| 344 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 345 | fprintf(output, ", unparsed\n"); |
| 346 | break; |
| 347 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 348 | fprintf(output, ", parameter\n"); |
| 349 | break; |
| 350 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 351 | fprintf(output, ", external parameter\n"); |
| 352 | break; |
| 353 | case XML_INTERNAL_PREDEFINED_ENTITY: |
| 354 | fprintf(output, ", predefined\n"); |
| 355 | break; |
| 356 | } |
| 357 | if (ent->ExternalID) { |
| 358 | fprintf(output, shift); |
| 359 | fprintf(output, " ExternalID=%s\n", ent->ExternalID); |
| 360 | } |
| 361 | if (ent->SystemID) { |
| 362 | fprintf(output, shift); |
| 363 | fprintf(output, " SystemID=%s\n", ent->SystemID); |
| 364 | } |
| 365 | if (ent->URI != NULL) { |
| 366 | fprintf(output, shift); |
| 367 | fprintf(output, " URI=%s\n", ent->URI); |
| 368 | } |
| 369 | if (ent->content) { |
| 370 | fprintf(output, shift); |
| 371 | fprintf(output, " content="); |
| 372 | xmlDebugDumpString(output, ent->content); |
| 373 | fprintf(output, "\n"); |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | * Do a bit of checking |
| 378 | */ |
| 379 | if (ent->parent == NULL) |
| 380 | fprintf(output, "PBM: Ent has no parent\n"); |
| 381 | if (ent->doc == NULL) |
| 382 | fprintf(output, "PBM: Ent has no doc\n"); |
| 383 | if ((ent->parent != NULL) && (ent->doc != ent->parent->doc)) |
| 384 | fprintf(output, "PBM: Ent doc differs from parent's one\n"); |
| 385 | if (ent->prev == NULL) { |
| 386 | if ((ent->parent != NULL) && (ent->parent->children != (xmlNodePtr)ent)) |
| 387 | fprintf(output, "PBM: Ent has no prev and not first of list\n"); |
| 388 | } else { |
| 389 | if (ent->prev->next != (xmlNodePtr) ent) |
| 390 | fprintf(output, "PBM: Ent prev->next : back link wrong\n"); |
| 391 | } |
| 392 | if (ent->next == NULL) { |
| 393 | if ((ent->parent != NULL) && (ent->parent->last != (xmlNodePtr) ent)) |
| 394 | fprintf(output, "PBM: Ent has no next and not last of list\n"); |
| 395 | } else { |
| 396 | if (ent->next->prev != (xmlNodePtr) ent) |
| 397 | fprintf(output, "PBM: Ent next->prev : forward link wrong\n"); |
| 398 | } |
| 399 | } |
| 400 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 401 | static void |
| 402 | xmlDebugDumpNamespace(FILE *output, xmlNsPtr ns, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 403 | int i; |
| 404 | char shift[100]; |
| 405 | |
| 406 | for (i = 0;((i < depth) && (i < 25));i++) |
| 407 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 408 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 409 | |
| 410 | fprintf(output, shift); |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 411 | |
| 412 | if (ns == NULL) { |
| 413 | fprintf(output, "namespace node is NULL\n"); |
| 414 | return; |
| 415 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 416 | if (ns->type != XML_NAMESPACE_DECL) { |
| 417 | fprintf(output, "invalid namespace node %d\n", ns->type); |
| 418 | return; |
| 419 | } |
| 420 | if (ns->href == NULL) { |
| 421 | if (ns->prefix != NULL) |
| 422 | fprintf(output, "incomplete namespace %s href=NULL\n", ns->prefix); |
| 423 | else |
| 424 | fprintf(output, "incomplete default namespace href=NULL\n"); |
| 425 | } else { |
| 426 | if (ns->prefix != NULL) |
| 427 | fprintf(output, "namespace %s href=", ns->prefix); |
| 428 | else |
| 429 | fprintf(output, "default namespace href="); |
| 430 | |
| 431 | xmlDebugDumpString(output, ns->href); |
| 432 | fprintf(output, "\n"); |
| 433 | } |
| 434 | } |
| 435 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 436 | static void |
| 437 | xmlDebugDumpNamespaceList(FILE *output, xmlNsPtr ns, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 438 | while (ns != NULL) { |
| 439 | xmlDebugDumpNamespace(output, ns, depth); |
| 440 | ns = ns->next; |
| 441 | } |
| 442 | } |
| 443 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 444 | static void |
| 445 | xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 446 | int i; |
| 447 | char shift[100]; |
| 448 | |
| 449 | for (i = 0;((i < depth) && (i < 25));i++) |
| 450 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 451 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 452 | |
| 453 | fprintf(output, shift); |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 454 | |
| 455 | if (ent == NULL) { |
| 456 | fprintf(output, "Entity is NULL\n"); |
| 457 | return; |
| 458 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 459 | switch (ent->etype) { |
| 460 | case XML_INTERNAL_GENERAL_ENTITY: |
| 461 | fprintf(output, "INTERNAL_GENERAL_ENTITY "); |
| 462 | break; |
| 463 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 464 | fprintf(output, "EXTERNAL_GENERAL_PARSED_ENTITY "); |
| 465 | break; |
| 466 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 467 | fprintf(output, "EXTERNAL_GENERAL_UNPARSED_ENTITY "); |
| 468 | break; |
| 469 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 470 | fprintf(output, "INTERNAL_PARAMETER_ENTITY "); |
| 471 | break; |
| 472 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 473 | fprintf(output, "EXTERNAL_PARAMETER_ENTITY "); |
| 474 | break; |
| 475 | default: |
| 476 | fprintf(output, "ENTITY_%d ! ", ent->etype); |
| 477 | } |
| 478 | fprintf(output, "%s\n", ent->name); |
| 479 | if (ent->ExternalID) { |
| 480 | fprintf(output, shift); |
| 481 | fprintf(output, "ExternalID=%s\n", ent->ExternalID); |
| 482 | } |
| 483 | if (ent->SystemID) { |
| 484 | fprintf(output, shift); |
| 485 | fprintf(output, "SystemID=%s\n", ent->SystemID); |
| 486 | } |
| 487 | if (ent->URI) { |
| 488 | fprintf(output, shift); |
| 489 | fprintf(output, "URI=%s\n", ent->URI); |
| 490 | } |
| 491 | if (ent->content) { |
| 492 | fprintf(output, shift); |
| 493 | fprintf(output, "content="); |
| 494 | xmlDebugDumpString(output, ent->content); |
| 495 | fprintf(output, "\n"); |
| 496 | } |
| 497 | } |
| 498 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 499 | /** |
| 500 | * xmlDebugDumpAttr: |
| 501 | * @output: the FILE * for the output |
| 502 | * @attr: the attribute |
| 503 | * @depth: the indentation level. |
| 504 | * |
| 505 | * Dumps debug information for the attribute |
| 506 | */ |
| 507 | void |
| 508 | xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 509 | int i; |
| 510 | char shift[100]; |
| 511 | |
| 512 | for (i = 0;((i < depth) && (i < 25));i++) |
| 513 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 514 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 515 | |
| 516 | fprintf(output, shift); |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 517 | |
| 518 | if (attr == NULL) { |
| 519 | fprintf(output, "Attr is NULL"); |
| 520 | return; |
| 521 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 522 | fprintf(output, "ATTRIBUTE "); |
| 523 | xmlDebugDumpString(output, attr->name); |
| 524 | fprintf(output, "\n"); |
| 525 | if (attr->children != NULL) |
| 526 | xmlDebugDumpNodeList(output, attr->children, depth + 1); |
| 527 | |
| 528 | /* |
| 529 | * Do a bit of checking |
| 530 | */ |
| 531 | if (attr->parent == NULL) |
| 532 | fprintf(output, "PBM: Attr has no parent\n"); |
| 533 | if (attr->doc == NULL) |
| 534 | fprintf(output, "PBM: Attr has no doc\n"); |
| 535 | if ((attr->parent != NULL) && (attr->doc != attr->parent->doc)) |
| 536 | fprintf(output, "PBM: Attr doc differs from parent's one\n"); |
| 537 | if (attr->prev == NULL) { |
| 538 | if ((attr->parent != NULL) && (attr->parent->properties != attr)) |
| 539 | fprintf(output, "PBM: Attr has no prev and not first of list\n"); |
| 540 | } else { |
| 541 | if (attr->prev->next != attr) |
| 542 | fprintf(output, "PBM: Attr prev->next : back link wrong\n"); |
| 543 | } |
| 544 | if (attr->next != NULL) { |
| 545 | if (attr->next->prev != attr) |
| 546 | fprintf(output, "PBM: Attr next->prev : forward link wrong\n"); |
| 547 | } |
| 548 | } |
| 549 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 550 | /** |
| 551 | * xmlDebugDumpAttrList: |
| 552 | * @output: the FILE * for the output |
| 553 | * @attr: the attribute list |
| 554 | * @depth: the indentation level. |
| 555 | * |
| 556 | * Dumps debug information for the attribute list |
| 557 | */ |
| 558 | void |
| 559 | xmlDebugDumpAttrList(FILE * output, xmlAttrPtr attr, int depth) |
| 560 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 561 | while (attr != NULL) { |
| 562 | xmlDebugDumpAttr(output, attr, depth); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 563 | attr = attr->next; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 567 | /** |
| 568 | * xmlDebugDumpOneNode: |
| 569 | * @output: the FILE * for the output |
| 570 | * @node: the node |
| 571 | * @depth: the indentation level. |
| 572 | * |
| 573 | * Dumps debug information for the element node, it is not recursive |
| 574 | */ |
| 575 | void |
| 576 | xmlDebugDumpOneNode(FILE * output, xmlNodePtr node, int depth) |
| 577 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 578 | int i; |
| 579 | char shift[100]; |
| 580 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 581 | for (i = 0; ((i < depth) && (i < 25)); i++) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 582 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 583 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 584 | |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 585 | if (node == NULL) { |
| 586 | fprintf(output, shift); |
| 587 | fprintf(output, "node is NULL\n"); |
| 588 | return; |
| 589 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 590 | switch (node->type) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 591 | case XML_ELEMENT_NODE: |
| 592 | fprintf(output, shift); |
| 593 | fprintf(output, "ELEMENT "); |
| 594 | if ((node->ns != NULL) && (node->ns->prefix != NULL)) { |
| 595 | xmlDebugDumpString(output, node->ns->prefix); |
| 596 | fprintf(output, ":"); |
| 597 | } |
| 598 | xmlDebugDumpString(output, node->name); |
| 599 | fprintf(output, "\n"); |
| 600 | break; |
| 601 | case XML_ATTRIBUTE_NODE: |
| 602 | fprintf(output, shift); |
| 603 | fprintf(output, "Error, ATTRIBUTE found here\n"); |
| 604 | break; |
| 605 | case XML_TEXT_NODE: |
| 606 | fprintf(output, shift); |
Daniel Veillard | b44025c | 2001-10-11 22:55:55 +0000 | [diff] [blame] | 607 | if (node->name == (const xmlChar *) xmlStringTextNoenc) |
Daniel Veillard | 567e1b4 | 2001-08-01 15:53:47 +0000 | [diff] [blame] | 608 | fprintf(output, "TEXT no enc\n"); |
| 609 | else |
| 610 | fprintf(output, "TEXT\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 611 | break; |
| 612 | case XML_CDATA_SECTION_NODE: |
| 613 | fprintf(output, shift); |
| 614 | fprintf(output, "CDATA_SECTION\n"); |
| 615 | break; |
| 616 | case XML_ENTITY_REF_NODE: |
| 617 | fprintf(output, shift); |
| 618 | fprintf(output, "ENTITY_REF(%s)\n", node->name); |
| 619 | break; |
| 620 | case XML_ENTITY_NODE: |
| 621 | fprintf(output, shift); |
| 622 | fprintf(output, "ENTITY\n"); |
| 623 | break; |
| 624 | case XML_PI_NODE: |
| 625 | fprintf(output, shift); |
| 626 | fprintf(output, "PI %s\n", node->name); |
| 627 | break; |
| 628 | case XML_COMMENT_NODE: |
| 629 | fprintf(output, shift); |
| 630 | fprintf(output, "COMMENT\n"); |
| 631 | break; |
| 632 | case XML_DOCUMENT_NODE: |
| 633 | case XML_HTML_DOCUMENT_NODE: |
| 634 | fprintf(output, shift); |
| 635 | fprintf(output, "Error, DOCUMENT found here\n"); |
| 636 | break; |
| 637 | case XML_DOCUMENT_TYPE_NODE: |
| 638 | fprintf(output, shift); |
| 639 | fprintf(output, "DOCUMENT_TYPE\n"); |
| 640 | break; |
| 641 | case XML_DOCUMENT_FRAG_NODE: |
| 642 | fprintf(output, shift); |
| 643 | fprintf(output, "DOCUMENT_FRAG\n"); |
| 644 | break; |
| 645 | case XML_NOTATION_NODE: |
| 646 | fprintf(output, shift); |
| 647 | fprintf(output, "NOTATION\n"); |
| 648 | break; |
| 649 | case XML_DTD_NODE: |
| 650 | xmlDebugDumpDtdNode(output, (xmlDtdPtr) node, depth); |
| 651 | return; |
| 652 | case XML_ELEMENT_DECL: |
| 653 | xmlDebugDumpElemDecl(output, (xmlElementPtr) node, depth); |
| 654 | return; |
| 655 | case XML_ATTRIBUTE_DECL: |
| 656 | xmlDebugDumpAttrDecl(output, (xmlAttributePtr) node, depth); |
| 657 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 658 | case XML_ENTITY_DECL: |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 659 | xmlDebugDumpEntityDecl(output, (xmlEntityPtr) node, depth); |
| 660 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 661 | case XML_NAMESPACE_DECL: |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 662 | xmlDebugDumpNamespace(output, (xmlNsPtr) node, depth); |
| 663 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 664 | case XML_XINCLUDE_START: |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 665 | fprintf(output, shift); |
| 666 | fprintf(output, "INCLUDE START\n"); |
| 667 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 668 | case XML_XINCLUDE_END: |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 669 | fprintf(output, shift); |
| 670 | fprintf(output, "INCLUDE END\n"); |
| 671 | return; |
| 672 | default: |
| 673 | fprintf(output, shift); |
| 674 | fprintf(output, "NODE_%d !!!\n", node->type); |
| 675 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 676 | } |
| 677 | if (node->doc == NULL) { |
| 678 | fprintf(output, shift); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 679 | fprintf(output, "doc == NULL !!!\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 680 | } |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 681 | if (node->nsDef != NULL) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 682 | xmlDebugDumpNamespaceList(output, node->nsDef, depth + 1); |
| 683 | if (node->properties != NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 684 | xmlDebugDumpAttrList(output, node->properties, depth + 1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 685 | if (node->type != XML_ENTITY_REF_NODE) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 686 | if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL)) { |
| 687 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 688 | shift[2 * i + 2] = shift[2 * i + 3] = 0; |
| 689 | fprintf(output, shift); |
| 690 | fprintf(output, "content="); |
| 691 | #ifndef XML_USE_BUFFER_CONTENT |
| 692 | xmlDebugDumpString(output, node->content); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 693 | #else |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 694 | xmlDebugDumpString(output, xmlBufferContent(node->content)); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 695 | #endif |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 696 | fprintf(output, "\n"); |
| 697 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 698 | } else { |
| 699 | xmlEntityPtr ent; |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 700 | |
| 701 | ent = xmlGetDocEntity(node->doc, node->name); |
| 702 | if (ent != NULL) |
| 703 | xmlDebugDumpEntity(output, ent, depth + 1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 704 | } |
| 705 | /* |
| 706 | * Do a bit of checking |
| 707 | */ |
| 708 | if (node->parent == NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 709 | fprintf(output, "PBM: Node has no parent\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 710 | if (node->doc == NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 711 | fprintf(output, "PBM: Node has no doc\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 712 | if ((node->parent != NULL) && (node->doc != node->parent->doc)) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 713 | fprintf(output, "PBM: Node doc differs from parent's one\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 714 | if (node->prev == NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 715 | if ((node->parent != NULL) && (node->parent->children != node)) |
| 716 | fprintf(output, |
| 717 | "PBM: Node has no prev and not first of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 718 | } else { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 719 | if (node->prev->next != node) |
| 720 | fprintf(output, "PBM: Node prev->next : back link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 721 | } |
| 722 | if (node->next == NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 723 | if ((node->parent != NULL) && (node->parent->last != node)) |
| 724 | fprintf(output, |
| 725 | "PBM: Node has no next and not last of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 726 | } else { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 727 | if (node->next->prev != node) |
| 728 | fprintf(output, "PBM: Node next->prev : forward link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 732 | /** |
| 733 | * xmlDebugDumpNode: |
| 734 | * @output: the FILE * for the output |
| 735 | * @node: the node |
| 736 | * @depth: the indentation level. |
| 737 | * |
| 738 | * Dumps debug information for the element node, it is recursive |
| 739 | */ |
| 740 | void |
| 741 | xmlDebugDumpNode(FILE * output, xmlNodePtr node, int depth) |
| 742 | { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 743 | if (node == NULL) { |
| 744 | int i; |
| 745 | char shift[100]; |
| 746 | |
| 747 | for (i = 0; ((i < depth) && (i < 25)); i++) |
| 748 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 749 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 750 | |
| 751 | fprintf(output, shift); |
| 752 | fprintf(output, "node is NULL\n"); |
| 753 | return; |
| 754 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 755 | xmlDebugDumpOneNode(output, node, depth); |
| 756 | if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 757 | xmlDebugDumpNodeList(output, node->children, depth + 1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 760 | /** |
| 761 | * xmlDebugDumpNodeList: |
| 762 | * @output: the FILE * for the output |
| 763 | * @node: the node list |
| 764 | * @depth: the indentation level. |
| 765 | * |
| 766 | * Dumps debug information for the list of element node, it is recursive |
| 767 | */ |
| 768 | void |
| 769 | xmlDebugDumpNodeList(FILE * output, xmlNodePtr node, int depth) |
| 770 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 771 | while (node != NULL) { |
| 772 | xmlDebugDumpNode(output, node, depth); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 773 | node = node->next; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
| 777 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 778 | /** |
| 779 | * xmlDebugDumpDocumentHead: |
| 780 | * @output: the FILE * for the output |
| 781 | * @doc: the document |
| 782 | * |
| 783 | * Dumps debug information cncerning the document, not recursive |
| 784 | */ |
| 785 | void |
| 786 | xmlDebugDumpDocumentHead(FILE * output, xmlDocPtr doc) |
| 787 | { |
| 788 | if (output == NULL) |
| 789 | output = stdout; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 790 | if (doc == NULL) { |
| 791 | fprintf(output, "DOCUMENT == NULL !\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 792 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | switch (doc->type) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 796 | case XML_ELEMENT_NODE: |
| 797 | fprintf(output, "Error, ELEMENT found here "); |
| 798 | break; |
| 799 | case XML_ATTRIBUTE_NODE: |
| 800 | fprintf(output, "Error, ATTRIBUTE found here\n"); |
| 801 | break; |
| 802 | case XML_TEXT_NODE: |
| 803 | fprintf(output, "Error, TEXT\n"); |
| 804 | break; |
| 805 | case XML_CDATA_SECTION_NODE: |
| 806 | fprintf(output, "Error, CDATA_SECTION\n"); |
| 807 | break; |
| 808 | case XML_ENTITY_REF_NODE: |
| 809 | fprintf(output, "Error, ENTITY_REF\n"); |
| 810 | break; |
| 811 | case XML_ENTITY_NODE: |
| 812 | fprintf(output, "Error, ENTITY\n"); |
| 813 | break; |
| 814 | case XML_PI_NODE: |
| 815 | fprintf(output, "Error, PI\n"); |
| 816 | break; |
| 817 | case XML_COMMENT_NODE: |
| 818 | fprintf(output, "Error, COMMENT\n"); |
| 819 | break; |
| 820 | case XML_DOCUMENT_NODE: |
| 821 | fprintf(output, "DOCUMENT\n"); |
| 822 | break; |
| 823 | case XML_HTML_DOCUMENT_NODE: |
| 824 | fprintf(output, "HTML DOCUMENT\n"); |
| 825 | break; |
| 826 | case XML_DOCUMENT_TYPE_NODE: |
| 827 | fprintf(output, "Error, DOCUMENT_TYPE\n"); |
| 828 | break; |
| 829 | case XML_DOCUMENT_FRAG_NODE: |
| 830 | fprintf(output, "Error, DOCUMENT_FRAG\n"); |
| 831 | break; |
| 832 | case XML_NOTATION_NODE: |
| 833 | fprintf(output, "Error, NOTATION\n"); |
| 834 | break; |
| 835 | default: |
| 836 | fprintf(output, "NODE_%d\n", doc->type); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 837 | } |
| 838 | if (doc->name != NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 839 | fprintf(output, "name="); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 840 | xmlDebugDumpString(output, BAD_CAST doc->name); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 841 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 842 | } |
| 843 | if (doc->version != NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 844 | fprintf(output, "version="); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 845 | xmlDebugDumpString(output, doc->version); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 846 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 847 | } |
| 848 | if (doc->encoding != NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 849 | fprintf(output, "encoding="); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 850 | xmlDebugDumpString(output, doc->encoding); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 851 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 852 | } |
| 853 | if (doc->URL != NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 854 | fprintf(output, "URL="); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 855 | xmlDebugDumpString(output, doc->URL); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 856 | fprintf(output, "\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 857 | } |
| 858 | if (doc->standalone) |
| 859 | fprintf(output, "standalone=true\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 860 | if (doc->oldNs != NULL) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 861 | xmlDebugDumpNamespaceList(output, doc->oldNs, 0); |
| 862 | } |
| 863 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 864 | /** |
| 865 | * xmlDebugDumpDocument: |
| 866 | * @output: the FILE * for the output |
| 867 | * @doc: the document |
| 868 | * |
| 869 | * Dumps debug information for the document, it's recursive |
| 870 | */ |
| 871 | void |
| 872 | xmlDebugDumpDocument(FILE * output, xmlDocPtr doc) |
| 873 | { |
| 874 | if (output == NULL) |
| 875 | output = stdout; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 876 | if (doc == NULL) { |
| 877 | fprintf(output, "DOCUMENT == NULL !\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 878 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 879 | } |
| 880 | xmlDebugDumpDocumentHead(output, doc); |
| 881 | if (((doc->type == XML_DOCUMENT_NODE) || |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 882 | (doc->type == XML_HTML_DOCUMENT_NODE)) && (doc->children != NULL)) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 883 | xmlDebugDumpNodeList(output, doc->children, 1); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 884 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 885 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 886 | /** |
| 887 | * xmlDebugDumpDTD: |
| 888 | * @output: the FILE * for the output |
| 889 | * @dtd: the DTD |
| 890 | * |
| 891 | * Dumps debug information for the DTD |
| 892 | */ |
| 893 | void |
| 894 | xmlDebugDumpDTD(FILE * output, xmlDtdPtr dtd) |
| 895 | { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 896 | if (dtd == NULL) { |
| 897 | fprintf(output, "DTD is NULL\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 898 | return; |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 899 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 900 | if (dtd->type != XML_DTD_NODE) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 901 | fprintf(output, "PBM: not a DTD\n"); |
| 902 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 903 | } |
| 904 | if (dtd->name != NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 905 | fprintf(output, "DTD(%s)", dtd->name); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 906 | else |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 907 | fprintf(output, "DTD"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 908 | if (dtd->ExternalID != NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 909 | fprintf(output, ", PUBLIC %s", dtd->ExternalID); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 910 | if (dtd->SystemID != NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 911 | fprintf(output, ", SYSTEM %s", dtd->SystemID); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 912 | fprintf(output, "\n"); |
| 913 | /* |
| 914 | * Do a bit of checking |
| 915 | */ |
| 916 | if ((dtd->parent != NULL) && (dtd->doc != dtd->parent->doc)) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 917 | fprintf(output, "PBM: DTD doc differs from parent's one\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 918 | if (dtd->prev == NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 919 | if ((dtd->parent != NULL) |
| 920 | && (dtd->parent->children != (xmlNodePtr) dtd)) |
| 921 | fprintf(output, |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 922 | "PBM: DTD has no prev and not first of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 923 | } else { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 924 | if (dtd->prev->next != (xmlNodePtr) dtd) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 925 | fprintf(output, "PBM: DTD prev->next : back link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 926 | } |
| 927 | if (dtd->next == NULL) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 928 | if ((dtd->parent != NULL) |
| 929 | && (dtd->parent->last != (xmlNodePtr) dtd)) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 930 | fprintf(output, "PBM: DTD has no next and not last of list\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 931 | } else { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 932 | if (dtd->next->prev != (xmlNodePtr) dtd) |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 933 | fprintf(output, "PBM: DTD next->prev : forward link wrong\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 934 | } |
| 935 | if (dtd->children == NULL) |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 936 | fprintf(output, " DTD is empty\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 937 | else |
| 938 | xmlDebugDumpNodeList(output, dtd->children, 1); |
| 939 | } |
| 940 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 941 | static void |
| 942 | xmlDebugDumpEntityCallback(xmlEntityPtr cur, FILE *output) { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 943 | if (cur == NULL) { |
| 944 | fprintf(output, "Entity is NULL"); |
| 945 | return; |
| 946 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 947 | fprintf(output, "%s : ", cur->name); |
| 948 | switch (cur->etype) { |
| 949 | case XML_INTERNAL_GENERAL_ENTITY: |
| 950 | fprintf(output, "INTERNAL GENERAL, "); |
| 951 | break; |
| 952 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 953 | fprintf(output, "EXTERNAL PARSED, "); |
| 954 | break; |
| 955 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 956 | fprintf(output, "EXTERNAL UNPARSED, "); |
| 957 | break; |
| 958 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 959 | fprintf(output, "INTERNAL PARAMETER, "); |
| 960 | break; |
| 961 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 962 | fprintf(output, "EXTERNAL PARAMETER, "); |
| 963 | break; |
| 964 | default: |
| 965 | fprintf(output, "UNKNOWN TYPE %d", |
| 966 | cur->etype); |
| 967 | } |
| 968 | if (cur->ExternalID != NULL) |
| 969 | fprintf(output, "ID \"%s\"", cur->ExternalID); |
| 970 | if (cur->SystemID != NULL) |
| 971 | fprintf(output, "SYSTEM \"%s\"", cur->SystemID); |
| 972 | if (cur->orig != NULL) |
| 973 | fprintf(output, "\n orig \"%s\"", cur->orig); |
Daniel Veillard | 7db3773 | 2001-07-12 01:20:08 +0000 | [diff] [blame] | 974 | if ((cur->type != XML_ELEMENT_NODE) && |
| 975 | (cur->content != NULL)) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 976 | fprintf(output, "\n content \"%s\"", cur->content); |
| 977 | fprintf(output, "\n"); |
| 978 | } |
| 979 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 980 | /** |
| 981 | * xmlDebugDumpEntities: |
| 982 | * @output: the FILE * for the output |
| 983 | * @doc: the document |
| 984 | * |
| 985 | * Dumps debug information for all the entities in use by the document |
| 986 | */ |
| 987 | void |
| 988 | xmlDebugDumpEntities(FILE * output, xmlDocPtr doc) |
| 989 | { |
| 990 | if (output == NULL) |
| 991 | output = stdout; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 992 | if (doc == NULL) { |
| 993 | fprintf(output, "DOCUMENT == NULL !\n"); |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 994 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | switch (doc->type) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 998 | case XML_ELEMENT_NODE: |
| 999 | fprintf(output, "Error, ELEMENT found here "); |
| 1000 | break; |
| 1001 | case XML_ATTRIBUTE_NODE: |
| 1002 | fprintf(output, "Error, ATTRIBUTE found here\n"); |
| 1003 | break; |
| 1004 | case XML_TEXT_NODE: |
| 1005 | fprintf(output, "Error, TEXT\n"); |
| 1006 | break; |
| 1007 | case XML_CDATA_SECTION_NODE: |
| 1008 | fprintf(output, "Error, CDATA_SECTION\n"); |
| 1009 | break; |
| 1010 | case XML_ENTITY_REF_NODE: |
| 1011 | fprintf(output, "Error, ENTITY_REF\n"); |
| 1012 | break; |
| 1013 | case XML_ENTITY_NODE: |
| 1014 | fprintf(output, "Error, ENTITY\n"); |
| 1015 | break; |
| 1016 | case XML_PI_NODE: |
| 1017 | fprintf(output, "Error, PI\n"); |
| 1018 | break; |
| 1019 | case XML_COMMENT_NODE: |
| 1020 | fprintf(output, "Error, COMMENT\n"); |
| 1021 | break; |
| 1022 | case XML_DOCUMENT_NODE: |
| 1023 | fprintf(output, "DOCUMENT\n"); |
| 1024 | break; |
| 1025 | case XML_HTML_DOCUMENT_NODE: |
| 1026 | fprintf(output, "HTML DOCUMENT\n"); |
| 1027 | break; |
| 1028 | case XML_DOCUMENT_TYPE_NODE: |
| 1029 | fprintf(output, "Error, DOCUMENT_TYPE\n"); |
| 1030 | break; |
| 1031 | case XML_DOCUMENT_FRAG_NODE: |
| 1032 | fprintf(output, "Error, DOCUMENT_FRAG\n"); |
| 1033 | break; |
| 1034 | case XML_NOTATION_NODE: |
| 1035 | fprintf(output, "Error, NOTATION\n"); |
| 1036 | break; |
| 1037 | default: |
| 1038 | fprintf(output, "NODE_%d\n", doc->type); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1039 | } |
| 1040 | if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1041 | xmlEntitiesTablePtr table = (xmlEntitiesTablePtr) |
| 1042 | doc->intSubset->entities; |
| 1043 | |
| 1044 | fprintf(output, "Entities in internal subset\n"); |
| 1045 | xmlHashScan(table, (xmlHashScanner) xmlDebugDumpEntityCallback, |
| 1046 | output); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1047 | } else |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1048 | fprintf(output, "No entities in internal subset\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1049 | if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1050 | xmlEntitiesTablePtr table = (xmlEntitiesTablePtr) |
| 1051 | doc->extSubset->entities; |
| 1052 | |
| 1053 | fprintf(output, "Entities in external subset\n"); |
| 1054 | xmlHashScan(table, (xmlHashScanner) xmlDebugDumpEntityCallback, |
| 1055 | output); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1056 | } else |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1057 | fprintf(output, "No entities in external subset\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1060 | /** |
| 1061 | * xmlLsCountNode: |
| 1062 | * @node: the node to count |
| 1063 | * |
| 1064 | * Count the children of @node. |
| 1065 | * |
| 1066 | * Returns the number of children of @node. |
| 1067 | */ |
| 1068 | int |
| 1069 | xmlLsCountNode(xmlNodePtr node) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1070 | int ret = 0; |
| 1071 | xmlNodePtr list = NULL; |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1072 | |
| 1073 | if (node == NULL) |
| 1074 | return(0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1075 | |
| 1076 | switch (node->type) { |
| 1077 | case XML_ELEMENT_NODE: |
| 1078 | list = node->children; |
| 1079 | break; |
| 1080 | case XML_DOCUMENT_NODE: |
| 1081 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 1082 | #ifdef LIBXML_DOCB_ENABLED |
| 1083 | case XML_DOCB_DOCUMENT_NODE: |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1084 | #endif |
| 1085 | list = ((xmlDocPtr) node)->children; |
| 1086 | break; |
| 1087 | case XML_ATTRIBUTE_NODE: |
| 1088 | list = ((xmlAttrPtr) node)->children; |
| 1089 | break; |
| 1090 | case XML_TEXT_NODE: |
| 1091 | case XML_CDATA_SECTION_NODE: |
| 1092 | case XML_PI_NODE: |
| 1093 | case XML_COMMENT_NODE: |
| 1094 | if (node->content != NULL) { |
| 1095 | #ifndef XML_USE_BUFFER_CONTENT |
| 1096 | ret = xmlStrlen(node->content); |
| 1097 | #else |
| 1098 | ret = xmlBufferLength(node->content); |
| 1099 | #endif |
| 1100 | } |
| 1101 | break; |
| 1102 | case XML_ENTITY_REF_NODE: |
| 1103 | case XML_DOCUMENT_TYPE_NODE: |
| 1104 | case XML_ENTITY_NODE: |
| 1105 | case XML_DOCUMENT_FRAG_NODE: |
| 1106 | case XML_NOTATION_NODE: |
| 1107 | case XML_DTD_NODE: |
| 1108 | case XML_ELEMENT_DECL: |
| 1109 | case XML_ATTRIBUTE_DECL: |
| 1110 | case XML_ENTITY_DECL: |
| 1111 | case XML_NAMESPACE_DECL: |
| 1112 | case XML_XINCLUDE_START: |
| 1113 | case XML_XINCLUDE_END: |
| 1114 | ret = 1; |
| 1115 | break; |
| 1116 | } |
| 1117 | for (;list != NULL;ret++) |
| 1118 | list = list->next; |
| 1119 | return(ret); |
| 1120 | } |
| 1121 | |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1122 | /** |
| 1123 | * xmlLsOneNode: |
| 1124 | * @output: the FILE * for the output |
| 1125 | * @node: the node to dump |
| 1126 | * |
| 1127 | * Dump to @output the type and name of @node. |
| 1128 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1129 | void |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1130 | xmlLsOneNode(FILE *output, xmlNodePtr node) { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1131 | if (node == NULL) { |
| 1132 | fprintf(output, "NULL\n"); |
| 1133 | return; |
| 1134 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1135 | switch (node->type) { |
| 1136 | case XML_ELEMENT_NODE: |
| 1137 | fprintf(output, "-"); |
| 1138 | break; |
| 1139 | case XML_ATTRIBUTE_NODE: |
| 1140 | fprintf(output, "a"); |
| 1141 | break; |
| 1142 | case XML_TEXT_NODE: |
| 1143 | fprintf(output, "t"); |
| 1144 | break; |
| 1145 | case XML_CDATA_SECTION_NODE: |
| 1146 | fprintf(output, "c"); |
| 1147 | break; |
| 1148 | case XML_ENTITY_REF_NODE: |
| 1149 | fprintf(output, "e"); |
| 1150 | break; |
| 1151 | case XML_ENTITY_NODE: |
| 1152 | fprintf(output, "E"); |
| 1153 | break; |
| 1154 | case XML_PI_NODE: |
| 1155 | fprintf(output, "p"); |
| 1156 | break; |
| 1157 | case XML_COMMENT_NODE: |
| 1158 | fprintf(output, "c"); |
| 1159 | break; |
| 1160 | case XML_DOCUMENT_NODE: |
| 1161 | fprintf(output, "d"); |
| 1162 | break; |
| 1163 | case XML_HTML_DOCUMENT_NODE: |
| 1164 | fprintf(output, "h"); |
| 1165 | break; |
| 1166 | case XML_DOCUMENT_TYPE_NODE: |
| 1167 | fprintf(output, "T"); |
| 1168 | break; |
| 1169 | case XML_DOCUMENT_FRAG_NODE: |
| 1170 | fprintf(output, "F"); |
| 1171 | break; |
| 1172 | case XML_NOTATION_NODE: |
| 1173 | fprintf(output, "N"); |
| 1174 | break; |
Daniel Veillard | e6a5519 | 2002-01-14 17:11:53 +0000 | [diff] [blame] | 1175 | case XML_NAMESPACE_DECL: |
| 1176 | fprintf(output, "n"); |
| 1177 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1178 | default: |
| 1179 | fprintf(output, "?"); |
| 1180 | } |
Daniel Veillard | e6a5519 | 2002-01-14 17:11:53 +0000 | [diff] [blame] | 1181 | if (node->type != XML_NAMESPACE_DECL) { |
| 1182 | if (node->properties != NULL) |
| 1183 | fprintf(output, "a"); |
| 1184 | else |
| 1185 | fprintf(output, "-"); |
| 1186 | if (node->nsDef != NULL) |
| 1187 | fprintf(output, "n"); |
| 1188 | else |
| 1189 | fprintf(output, "-"); |
| 1190 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1191 | |
| 1192 | fprintf(output, " %8d ", xmlLsCountNode(node)); |
| 1193 | |
| 1194 | switch (node->type) { |
| 1195 | case XML_ELEMENT_NODE: |
| 1196 | if (node->name != NULL) |
| 1197 | fprintf(output, "%s", node->name); |
| 1198 | break; |
| 1199 | case XML_ATTRIBUTE_NODE: |
| 1200 | if (node->name != NULL) |
| 1201 | fprintf(output, "%s", node->name); |
| 1202 | break; |
| 1203 | case XML_TEXT_NODE: |
| 1204 | if (node->content != NULL) { |
| 1205 | #ifndef XML_USE_BUFFER_CONTENT |
| 1206 | xmlDebugDumpString(output, node->content); |
| 1207 | #else |
| 1208 | xmlDebugDumpString(output, xmlBufferContent(node->content)); |
| 1209 | #endif |
| 1210 | } |
| 1211 | break; |
| 1212 | case XML_CDATA_SECTION_NODE: |
| 1213 | break; |
| 1214 | case XML_ENTITY_REF_NODE: |
| 1215 | if (node->name != NULL) |
| 1216 | fprintf(output, "%s", node->name); |
| 1217 | break; |
| 1218 | case XML_ENTITY_NODE: |
| 1219 | if (node->name != NULL) |
| 1220 | fprintf(output, "%s", node->name); |
| 1221 | break; |
| 1222 | case XML_PI_NODE: |
| 1223 | if (node->name != NULL) |
| 1224 | fprintf(output, "%s", node->name); |
| 1225 | break; |
| 1226 | case XML_COMMENT_NODE: |
| 1227 | break; |
| 1228 | case XML_DOCUMENT_NODE: |
| 1229 | break; |
| 1230 | case XML_HTML_DOCUMENT_NODE: |
| 1231 | break; |
| 1232 | case XML_DOCUMENT_TYPE_NODE: |
| 1233 | break; |
| 1234 | case XML_DOCUMENT_FRAG_NODE: |
| 1235 | break; |
| 1236 | case XML_NOTATION_NODE: |
| 1237 | break; |
Daniel Veillard | e6a5519 | 2002-01-14 17:11:53 +0000 | [diff] [blame] | 1238 | case XML_NAMESPACE_DECL: { |
| 1239 | xmlNsPtr ns = (xmlNsPtr) node; |
| 1240 | |
| 1241 | if (ns->prefix == NULL) |
| 1242 | fprintf(output, "default -> %s", ns->href); |
| 1243 | else |
| 1244 | fprintf(output, "%s -> %s", ns->prefix, ns->href); |
| 1245 | break; |
| 1246 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1247 | default: |
| 1248 | if (node->name != NULL) |
| 1249 | fprintf(output, "%s", node->name); |
| 1250 | } |
| 1251 | fprintf(output, "\n"); |
| 1252 | } |
| 1253 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1254 | /** |
| 1255 | * xmlBoolToText: |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1256 | * @boolval: a bool to turn into text |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1257 | * |
| 1258 | * Convenient way to turn bool into text |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1259 | * |
| 1260 | * Returns a pointer to either "True" or "False" |
| 1261 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1262 | const char * |
Daniel Veillard | ebd38c5 | 2001-11-01 08:38:12 +0000 | [diff] [blame] | 1263 | xmlBoolToText(int boolval) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1264 | { |
Daniel Veillard | ebd38c5 | 2001-11-01 08:38:12 +0000 | [diff] [blame] | 1265 | if (boolval) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1266 | return("True"); |
| 1267 | else |
| 1268 | return("False"); |
| 1269 | } |
| 1270 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1271 | /**************************************************************** |
| 1272 | * * |
| 1273 | * The XML shell related functions * |
| 1274 | * * |
| 1275 | ****************************************************************/ |
| 1276 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1277 | |
| 1278 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1279 | /* |
| 1280 | * TODO: Improvement/cleanups for the XML shell |
| 1281 | * - allow to shell out an editor on a subpart |
| 1282 | * - cleanup function registrations (with help) and calling |
| 1283 | * - provide registration routines |
| 1284 | */ |
| 1285 | |
| 1286 | /** |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1287 | * xmlShellPrintXPathError: |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1288 | * @errorType: valid xpath error id |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1289 | * @arg: the argument that cause xpath to fail |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1290 | * |
| 1291 | * Print the xpath error to libxml default error channel |
| 1292 | */ |
| 1293 | void |
| 1294 | xmlShellPrintXPathError(int errorType, const char *arg) |
| 1295 | { |
| 1296 | const char *default_arg = "Result"; |
| 1297 | |
| 1298 | if (!arg) |
| 1299 | arg = default_arg; |
| 1300 | |
| 1301 | switch (errorType) { |
| 1302 | case XPATH_UNDEFINED: |
| 1303 | xmlGenericError(xmlGenericErrorContext, |
| 1304 | "%s: no such node\n", arg); |
| 1305 | break; |
| 1306 | |
| 1307 | case XPATH_BOOLEAN: |
| 1308 | xmlGenericError(xmlGenericErrorContext, |
| 1309 | "%s is a Boolean\n", arg); |
| 1310 | break; |
| 1311 | case XPATH_NUMBER: |
| 1312 | xmlGenericError(xmlGenericErrorContext, |
| 1313 | "%s is a number\n", arg); |
| 1314 | break; |
| 1315 | case XPATH_STRING: |
| 1316 | xmlGenericError(xmlGenericErrorContext, |
| 1317 | "%s is a string\n", arg); |
| 1318 | break; |
| 1319 | case XPATH_POINT: |
| 1320 | xmlGenericError(xmlGenericErrorContext, |
| 1321 | "%s is a point\n", arg); |
| 1322 | break; |
| 1323 | case XPATH_RANGE: |
| 1324 | xmlGenericError(xmlGenericErrorContext, |
| 1325 | "%s is a range\n", arg); |
| 1326 | break; |
| 1327 | case XPATH_LOCATIONSET: |
| 1328 | xmlGenericError(xmlGenericErrorContext, |
| 1329 | "%s is a range\n", arg); |
| 1330 | break; |
| 1331 | case XPATH_USERS: |
| 1332 | xmlGenericError(xmlGenericErrorContext, |
| 1333 | "%s is user-defined\n", arg); |
| 1334 | break; |
| 1335 | case XPATH_XSLT_TREE: |
| 1336 | xmlGenericError(xmlGenericErrorContext, |
| 1337 | "%s is an XSLT value tree\n", arg); |
| 1338 | break; |
| 1339 | } |
| 1340 | xmlGenericError(xmlGenericErrorContext, |
| 1341 | "Try casting the result string function (xpath builtin)\n", |
| 1342 | arg); |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | /** |
| 1347 | * xmlShellPrintNode: |
| 1348 | * @node : a non-null node to print to stdout |
| 1349 | * |
| 1350 | * Print node to stdout |
| 1351 | */ |
| 1352 | void |
| 1353 | xmlShellPrintNode(xmlNodePtr node) |
| 1354 | { |
| 1355 | if (!node) |
| 1356 | return; |
| 1357 | |
| 1358 | if (node->type == XML_DOCUMENT_NODE) |
| 1359 | xmlDocDump(stdout, (xmlDocPtr) node); |
| 1360 | else if (node->type == XML_ATTRIBUTE_NODE) |
| 1361 | xmlDebugDumpAttrList(stdout, (xmlAttrPtr) node, 0); |
| 1362 | else |
| 1363 | xmlElemDump(stdout, node->doc, node); |
| 1364 | |
| 1365 | fprintf(stdout, "\n"); |
| 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | /** |
| 1370 | * xmlShellPrintXPathResult: |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 1371 | * @list: a valid result generated by an xpath evaluation |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1372 | * |
| 1373 | * Prints result to stdout |
| 1374 | */ |
| 1375 | void |
| 1376 | xmlShellPrintXPathResult(xmlXPathObjectPtr list) |
| 1377 | { |
| 1378 | int i = 0; |
| 1379 | |
| 1380 | if (list != NULL) { |
| 1381 | switch (list->type) { |
| 1382 | case XPATH_NODESET:{ |
| 1383 | int indx; |
| 1384 | |
| 1385 | if (list->nodesetval) { |
| 1386 | for (indx = 0; indx < list->nodesetval->nodeNr; |
| 1387 | indx++) { |
| 1388 | if (i > 0) |
| 1389 | fprintf(stderr, " -------\n"); |
| 1390 | xmlShellPrintNode(list->nodesetval-> |
| 1391 | nodeTab[indx]); |
| 1392 | } |
| 1393 | } else { |
| 1394 | xmlGenericError(xmlGenericErrorContext, |
| 1395 | "Empty node set\n"); |
| 1396 | } |
| 1397 | break; |
| 1398 | } |
| 1399 | case XPATH_BOOLEAN: |
| 1400 | xmlGenericError(xmlGenericErrorContext, |
| 1401 | "Is a Boolean:%s\n", |
| 1402 | xmlBoolToText(list->boolval)); |
| 1403 | break; |
| 1404 | case XPATH_NUMBER: |
| 1405 | xmlGenericError(xmlGenericErrorContext, |
| 1406 | "Is a number:%0g\n", list->floatval); |
| 1407 | break; |
| 1408 | case XPATH_STRING: |
| 1409 | xmlGenericError(xmlGenericErrorContext, |
| 1410 | "Is a string:%s\n", list->stringval); |
| 1411 | break; |
| 1412 | |
| 1413 | default: |
| 1414 | xmlShellPrintXPathError(list->type, NULL); |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1420 | * xmlShellList: |
| 1421 | * @ctxt: the shell context |
| 1422 | * @arg: unused |
| 1423 | * @node: a node |
| 1424 | * @node2: unused |
| 1425 | * |
| 1426 | * Implements the XML shell function "ls" |
| 1427 | * Does an Unix like listing of the given node (like a directory) |
| 1428 | * |
| 1429 | * Returns 0 |
| 1430 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1431 | int |
| 1432 | xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 1433 | char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, |
| 1434 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1435 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1436 | xmlNodePtr cur; |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1437 | if (node == NULL) { |
| 1438 | fprintf(stdout, "NULL\n"); |
| 1439 | return (0); |
| 1440 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1441 | if ((node->type == XML_DOCUMENT_NODE) || |
| 1442 | (node->type == XML_HTML_DOCUMENT_NODE)) { |
| 1443 | cur = ((xmlDocPtr) node)->children; |
Daniel Veillard | e6a5519 | 2002-01-14 17:11:53 +0000 | [diff] [blame] | 1444 | } else if (node->type == XML_NAMESPACE_DECL) { |
| 1445 | xmlLsOneNode(stdout, node); |
| 1446 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1447 | } else if (node->children != NULL) { |
| 1448 | cur = node->children; |
| 1449 | } else { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1450 | xmlLsOneNode(stdout, node); |
| 1451 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1452 | } |
| 1453 | while (cur != NULL) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1454 | xmlLsOneNode(stdout, cur); |
| 1455 | cur = cur->next; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1456 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1457 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /** |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1461 | * xmlShellBase: |
| 1462 | * @ctxt: the shell context |
| 1463 | * @arg: unused |
| 1464 | * @node: a node |
| 1465 | * @node2: unused |
| 1466 | * |
| 1467 | * Implements the XML shell function "base" |
| 1468 | * dumps the current XML base of the node |
| 1469 | * |
| 1470 | * Returns 0 |
| 1471 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1472 | int |
| 1473 | xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 1474 | char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, |
| 1475 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1476 | { |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1477 | xmlChar *base; |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1478 | if (node == NULL) { |
| 1479 | fprintf(stdout, "NULL\n"); |
| 1480 | return (0); |
| 1481 | } |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1482 | |
| 1483 | base = xmlNodeGetBase(node->doc, node); |
| 1484 | |
| 1485 | if (base == NULL) { |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1486 | fprintf(stdout, " No base found !!!\n"); |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1487 | } else { |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1488 | fprintf(stdout, "%s\n", base); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1489 | xmlFree(base); |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1490 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1491 | return (0); |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /** |
Daniel Veillard | cfa0d81 | 2002-01-17 08:46:58 +0000 | [diff] [blame] | 1495 | * xmlShellSetBase: |
| 1496 | * @ctxt: the shell context |
| 1497 | * @arg: the new base |
| 1498 | * @node: a node |
| 1499 | * @node2: unused |
| 1500 | * |
| 1501 | * Implements the XML shell function "setbase" |
| 1502 | * change the current XML base of the node |
| 1503 | * |
| 1504 | * Returns 0 |
| 1505 | */ |
| 1506 | static int |
| 1507 | xmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 1508 | char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, |
| 1509 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1510 | { |
| 1511 | xmlNodeSetBase(node, (xmlChar*) arg); |
| 1512 | return (0); |
| 1513 | } |
| 1514 | |
| 1515 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1516 | * xmlShellDir: |
| 1517 | * @ctxt: the shell context |
| 1518 | * @arg: unused |
| 1519 | * @node: a node |
| 1520 | * @node2: unused |
| 1521 | * |
| 1522 | * Implements the XML shell function "dir" |
| 1523 | * dumps informations about the node (namespace, attributes, content). |
| 1524 | * |
| 1525 | * Returns 0 |
| 1526 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1527 | int |
| 1528 | xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 1529 | char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, |
| 1530 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1531 | { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1532 | if (node == NULL) { |
| 1533 | fprintf(stdout, "NULL\n"); |
| 1534 | return (0); |
| 1535 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1536 | if ((node->type == XML_DOCUMENT_NODE) || |
| 1537 | (node->type == XML_HTML_DOCUMENT_NODE)) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1538 | xmlDebugDumpDocumentHead(stdout, (xmlDocPtr) node); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1539 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1540 | xmlDebugDumpAttr(stdout, (xmlAttrPtr) node, 0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1541 | } else { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1542 | xmlDebugDumpOneNode(stdout, node, 0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1543 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1544 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | /** |
| 1548 | * xmlShellCat: |
| 1549 | * @ctxt: the shell context |
| 1550 | * @arg: unused |
| 1551 | * @node: a node |
| 1552 | * @node2: unused |
| 1553 | * |
| 1554 | * Implements the XML shell function "cat" |
| 1555 | * dumps the serialization node content (XML or HTML). |
| 1556 | * |
| 1557 | * Returns 0 |
| 1558 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1559 | int |
| 1560 | xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, |
| 1561 | xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1562 | { |
Daniel Veillard | 5e926fa | 2002-01-22 21:44:25 +0000 | [diff] [blame^] | 1563 | if (node == NULL) { |
| 1564 | fprintf(stdout, "NULL\n"); |
| 1565 | return (0); |
| 1566 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1567 | if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) { |
| 1568 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1569 | if (node->type == XML_HTML_DOCUMENT_NODE) |
| 1570 | htmlDocDump(stdout, (htmlDocPtr) node); |
| 1571 | else |
| 1572 | htmlNodeDumpFile(stdout, ctxt->doc, node); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1573 | #else |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1574 | if (node->type == XML_DOCUMENT_NODE) |
| 1575 | xmlDocDump(stdout, (xmlDocPtr) node); |
| 1576 | else |
| 1577 | xmlElemDump(stdout, ctxt->doc, node); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1578 | #endif /* LIBXML_HTML_ENABLED */ |
| 1579 | } else { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1580 | if (node->type == XML_DOCUMENT_NODE) |
| 1581 | xmlDocDump(stdout, (xmlDocPtr) node); |
| 1582 | else |
| 1583 | xmlElemDump(stdout, ctxt->doc, node); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1584 | } |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1585 | fprintf(stdout, "\n"); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1586 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * xmlShellLoad: |
| 1591 | * @ctxt: the shell context |
| 1592 | * @filename: the file name |
| 1593 | * @node: unused |
| 1594 | * @node2: unused |
| 1595 | * |
| 1596 | * Implements the XML shell function "load" |
| 1597 | * loads a new document specified by the filename |
| 1598 | * |
| 1599 | * Returns 0 or -1 if loading failed |
| 1600 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1601 | int |
| 1602 | xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename, |
| 1603 | xmlNodePtr node ATTRIBUTE_UNUSED, |
| 1604 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1605 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1606 | xmlDocPtr doc; |
| 1607 | int html = 0; |
| 1608 | |
| 1609 | if (ctxt->doc != NULL) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1610 | html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1611 | |
| 1612 | if (html) { |
| 1613 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1614 | doc = htmlParseFile(filename, NULL); |
| 1615 | #else |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1616 | fprintf(stdout, "HTML support not compiled in\n"); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1617 | doc = NULL; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1618 | #endif /* LIBXML_HTML_ENABLED */ |
| 1619 | } else { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1620 | doc = xmlParseFile(filename); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1621 | } |
| 1622 | if (doc != NULL) { |
| 1623 | if (ctxt->loaded == 1) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1624 | xmlFreeDoc(ctxt->doc); |
| 1625 | } |
| 1626 | ctxt->loaded = 1; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1627 | #ifdef LIBXML_XPATH_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1628 | xmlXPathFreeContext(ctxt->pctxt); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1629 | #endif /* LIBXML_XPATH_ENABLED */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1630 | xmlFree(ctxt->filename); |
| 1631 | ctxt->doc = doc; |
| 1632 | ctxt->node = (xmlNodePtr) doc; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1633 | #ifdef LIBXML_XPATH_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1634 | ctxt->pctxt = xmlXPathNewContext(doc); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1635 | #endif /* LIBXML_XPATH_ENABLED */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1636 | ctxt->filename = (char *) xmlStrdup((xmlChar *) filename); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1637 | } else |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1638 | return (-1); |
| 1639 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | /** |
| 1643 | * xmlShellWrite: |
| 1644 | * @ctxt: the shell context |
| 1645 | * @filename: the file name |
| 1646 | * @node: a node in the tree |
| 1647 | * @node2: unused |
| 1648 | * |
| 1649 | * Implements the XML shell function "write" |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1650 | * Write the current node to the filename, it saves the serialization |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1651 | * of the subtree under the @node specified |
| 1652 | * |
| 1653 | * Returns 0 or -1 in case of error |
| 1654 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1655 | int |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1656 | xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node, |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1657 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1658 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1659 | if (node == NULL) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1660 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1661 | if ((filename == NULL) || (filename[0] == 0)) { |
| 1662 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1663 | "Write command requires a filename argument\n"); |
| 1664 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1665 | } |
| 1666 | #ifdef W_OK |
| 1667 | if (access((char *) filename, W_OK)) { |
| 1668 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1669 | "Cannot write to %s\n", filename); |
| 1670 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1671 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1672 | #endif |
| 1673 | switch (node->type) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1674 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1675 | if (xmlSaveFile((char *) filename, ctxt->doc) < -1) { |
| 1676 | xmlGenericError(xmlGenericErrorContext, |
| 1677 | "Failed to write to %s\n", filename); |
| 1678 | return (-1); |
| 1679 | } |
| 1680 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1681 | case XML_HTML_DOCUMENT_NODE: |
| 1682 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1683 | if (htmlSaveFile((char *) filename, ctxt->doc) < 0) { |
| 1684 | xmlGenericError(xmlGenericErrorContext, |
| 1685 | "Failed to write to %s\n", filename); |
| 1686 | return (-1); |
| 1687 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1688 | #else |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1689 | if (xmlSaveFile((char *) filename, ctxt->doc) < -1) { |
| 1690 | xmlGenericError(xmlGenericErrorContext, |
| 1691 | "Failed to write to %s\n", filename); |
| 1692 | return (-1); |
| 1693 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1694 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1695 | break; |
| 1696 | default:{ |
| 1697 | FILE *f; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1698 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1699 | f = fopen((char *) filename, "w"); |
| 1700 | if (f == NULL) { |
| 1701 | xmlGenericError(xmlGenericErrorContext, |
| 1702 | "Failed to write to %s\n", filename); |
| 1703 | return (-1); |
| 1704 | } |
| 1705 | xmlElemDump(f, ctxt->doc, node); |
| 1706 | fclose(f); |
| 1707 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1708 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1709 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * xmlShellSave: |
| 1714 | * @ctxt: the shell context |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1715 | * @filename: the file name (optional) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1716 | * @node: unused |
| 1717 | * @node2: unused |
| 1718 | * |
| 1719 | * Implements the XML shell function "save" |
| 1720 | * Write the current document to the filename, or it's original name |
| 1721 | * |
| 1722 | * Returns 0 or -1 in case of error |
| 1723 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1724 | int |
| 1725 | xmlShellSave(xmlShellCtxtPtr ctxt, char *filename, |
| 1726 | xmlNodePtr node ATTRIBUTE_UNUSED, |
| 1727 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1728 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1729 | if (ctxt->doc == NULL) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1730 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1731 | if ((filename == NULL) || (filename[0] == 0)) |
| 1732 | filename = ctxt->filename; |
| 1733 | #ifdef W_OK |
| 1734 | if (access((char *) filename, W_OK)) { |
| 1735 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1736 | "Cannot save to %s\n", filename); |
| 1737 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1738 | } |
| 1739 | #endif |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1740 | switch (ctxt->doc->type) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1741 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1742 | if (xmlSaveFile((char *) filename, ctxt->doc) < 0) { |
| 1743 | xmlGenericError(xmlGenericErrorContext, |
| 1744 | "Failed to save to %s\n", filename); |
| 1745 | } |
| 1746 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1747 | case XML_HTML_DOCUMENT_NODE: |
| 1748 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1749 | if (htmlSaveFile((char *) filename, ctxt->doc) < 0) { |
| 1750 | xmlGenericError(xmlGenericErrorContext, |
| 1751 | "Failed to save to %s\n", filename); |
| 1752 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1753 | #else |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1754 | if (xmlSaveFile((char *) filename, ctxt->doc) < 0) { |
| 1755 | xmlGenericError(xmlGenericErrorContext, |
| 1756 | "Failed to save to %s\n", filename); |
| 1757 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1758 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1759 | break; |
| 1760 | default: |
| 1761 | xmlGenericError(xmlGenericErrorContext, |
| 1762 | "To save to subparts of a document use the 'write' command\n"); |
| 1763 | return (-1); |
| 1764 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1765 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1766 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * xmlShellValidate: |
| 1771 | * @ctxt: the shell context |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1772 | * @dtd: the DTD URI (optional) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1773 | * @node: unused |
| 1774 | * @node2: unused |
| 1775 | * |
| 1776 | * Implements the XML shell function "validate" |
| 1777 | * Validate the document, if a DTD path is provided, then the validation |
| 1778 | * is done against the given DTD. |
| 1779 | * |
| 1780 | * Returns 0 or -1 in case of error |
| 1781 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1782 | int |
| 1783 | xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, |
| 1784 | xmlNodePtr node ATTRIBUTE_UNUSED, |
| 1785 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1786 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1787 | xmlValidCtxt vctxt; |
| 1788 | int res = -1; |
| 1789 | |
| 1790 | vctxt.userData = stderr; |
| 1791 | vctxt.error = (xmlValidityErrorFunc) fprintf; |
| 1792 | vctxt.warning = (xmlValidityWarningFunc) fprintf; |
| 1793 | |
| 1794 | if ((dtd == NULL) || (dtd[0] == 0)) { |
| 1795 | res = xmlValidateDocument(&vctxt, ctxt->doc); |
| 1796 | } else { |
| 1797 | xmlDtdPtr subset; |
| 1798 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1799 | subset = xmlParseDTD(NULL, (xmlChar *) dtd); |
| 1800 | if (subset != NULL) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1801 | res = xmlValidateDtd(&vctxt, ctxt->doc, subset); |
| 1802 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1803 | xmlFreeDtd(subset); |
| 1804 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1805 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1806 | return (res); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /** |
| 1810 | * xmlShellDu: |
| 1811 | * @ctxt: the shell context |
| 1812 | * @arg: unused |
| 1813 | * @tree: a node defining a subtree |
| 1814 | * @node2: unused |
| 1815 | * |
| 1816 | * Implements the XML shell function "du" |
| 1817 | * show the structure of the subtree under node @tree |
| 1818 | * If @tree is null, the command works on the current node. |
| 1819 | * |
| 1820 | * Returns 0 or -1 in case of error |
| 1821 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1822 | int |
| 1823 | xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 1824 | char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree, |
| 1825 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1826 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1827 | xmlNodePtr node; |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1828 | int indent = 0, i; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1829 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1830 | if (tree == NULL) |
| 1831 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1832 | node = tree; |
| 1833 | while (node != NULL) { |
| 1834 | if ((node->type == XML_DOCUMENT_NODE) || |
| 1835 | (node->type == XML_HTML_DOCUMENT_NODE)) { |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1836 | fprintf(stdout, "/\n"); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1837 | } else if (node->type == XML_ELEMENT_NODE) { |
| 1838 | for (i = 0; i < indent; i++) |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 1839 | fprintf(stdout, " "); |
| 1840 | fprintf(stdout, "%s\n", node->name); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1841 | } else { |
| 1842 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1843 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1844 | /* |
| 1845 | * Browse the full subtree, deep first |
| 1846 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1847 | |
| 1848 | if ((node->type == XML_DOCUMENT_NODE) || |
| 1849 | (node->type == XML_HTML_DOCUMENT_NODE)) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1850 | node = ((xmlDocPtr) node)->children; |
| 1851 | } else if ((node->children != NULL) |
| 1852 | && (node->type != XML_ENTITY_REF_NODE)) { |
| 1853 | /* deep first */ |
| 1854 | node = node->children; |
| 1855 | indent++; |
| 1856 | } else if ((node != tree) && (node->next != NULL)) { |
| 1857 | /* then siblings */ |
| 1858 | node = node->next; |
| 1859 | } else if (node != tree) { |
| 1860 | /* go up to parents->next if needed */ |
| 1861 | while (node != tree) { |
| 1862 | if (node->parent != NULL) { |
| 1863 | node = node->parent; |
| 1864 | indent--; |
| 1865 | } |
| 1866 | if ((node != tree) && (node->next != NULL)) { |
| 1867 | node = node->next; |
| 1868 | break; |
| 1869 | } |
| 1870 | if (node->parent == NULL) { |
| 1871 | node = NULL; |
| 1872 | break; |
| 1873 | } |
| 1874 | if (node == tree) { |
| 1875 | node = NULL; |
| 1876 | break; |
| 1877 | } |
| 1878 | } |
| 1879 | /* exit condition */ |
| 1880 | if (node == tree) |
| 1881 | node = NULL; |
| 1882 | } else |
| 1883 | node = NULL; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1884 | } |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1885 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /** |
| 1889 | * xmlShellPwd: |
| 1890 | * @ctxt: the shell context |
| 1891 | * @buffer: the output buffer |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 1892 | * @node: a node |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1893 | * @node2: unused |
| 1894 | * |
| 1895 | * Implements the XML shell function "pwd" |
| 1896 | * Show the full path from the root to the node, if needed building |
| 1897 | * thumblers when similar elements exists at a given ancestor level. |
| 1898 | * The output is compatible with XPath commands. |
| 1899 | * |
| 1900 | * Returns 0 or -1 in case of error |
| 1901 | */ |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1902 | int |
| 1903 | xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, |
| 1904 | xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 1905 | { |
Daniel Veillard | c6e013a | 2001-11-10 10:08:57 +0000 | [diff] [blame] | 1906 | xmlChar *path; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1907 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1908 | if (node == NULL) |
| 1909 | return (-1); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1910 | |
Daniel Veillard | c6e013a | 2001-11-10 10:08:57 +0000 | [diff] [blame] | 1911 | path = xmlGetNodePath(node); |
| 1912 | if (path == NULL) |
| 1913 | return (-1); |
| 1914 | |
| 1915 | /* |
| 1916 | * This test prevents buffer overflow, because this routine |
| 1917 | * is only called by xmlShell, in which the second argument is |
| 1918 | * 500 chars long. |
| 1919 | * It is a dirty hack before a cleaner solution is found. |
| 1920 | * Documentation should mention that the second argument must |
| 1921 | * be at least 500 chars long, and could be stripped if too long. |
| 1922 | */ |
| 1923 | snprintf(buffer, 499, "%s", path); |
| 1924 | buffer[499] = '0'; |
| 1925 | xmlFree(path); |
| 1926 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1927 | return (0); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * xmlShell |
| 1932 | * @doc: the initial document |
| 1933 | * @filename: the output buffer |
| 1934 | * @input: the line reading function |
| 1935 | * @output: the output FILE* |
| 1936 | * |
| 1937 | * Implements the XML shell |
| 1938 | * This allow to load, validate, view, modify and save a document |
| 1939 | * using a environment similar to a UNIX commandline. |
| 1940 | */ |
| 1941 | void |
| 1942 | xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1943 | FILE * output) |
| 1944 | { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1945 | char prompt[500] = "/ > "; |
| 1946 | char *cmdline = NULL, *cur; |
| 1947 | int nbargs; |
| 1948 | char command[100]; |
| 1949 | char arg[400]; |
| 1950 | int i; |
| 1951 | xmlShellCtxtPtr ctxt; |
| 1952 | xmlXPathObjectPtr list; |
| 1953 | |
| 1954 | if (doc == NULL) |
| 1955 | return; |
| 1956 | if (filename == NULL) |
| 1957 | return; |
| 1958 | if (input == NULL) |
| 1959 | return; |
| 1960 | if (output == NULL) |
| 1961 | return; |
| 1962 | ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt)); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1963 | if (ctxt == NULL) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1964 | return; |
| 1965 | ctxt->loaded = 0; |
| 1966 | ctxt->doc = doc; |
| 1967 | ctxt->input = input; |
| 1968 | ctxt->output = output; |
| 1969 | ctxt->filename = (char *) xmlStrdup((xmlChar *) filename); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1970 | ctxt->node = (xmlNodePtr) ctxt->doc; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1971 | |
| 1972 | #ifdef LIBXML_XPATH_ENABLED |
| 1973 | ctxt->pctxt = xmlXPathNewContext(ctxt->doc); |
| 1974 | if (ctxt->pctxt == NULL) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1975 | xmlFree(ctxt); |
| 1976 | return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1977 | } |
| 1978 | #endif /* LIBXML_XPATH_ENABLED */ |
| 1979 | while (1) { |
| 1980 | if (ctxt->node == (xmlNodePtr) ctxt->doc) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1981 | sprintf(prompt, "%s > ", "/"); |
| 1982 | else if (ctxt->node->name) |
| 1983 | snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1984 | else |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1985 | sprintf(prompt, "? > "); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1986 | prompt[sizeof(prompt) - 1] = 0; |
| 1987 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1988 | /* |
| 1989 | * Get a new command line |
| 1990 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1991 | cmdline = ctxt->input(prompt); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1992 | if (cmdline == NULL) |
| 1993 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1994 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 1995 | /* |
| 1996 | * Parse the command itself |
| 1997 | */ |
| 1998 | cur = cmdline; |
| 1999 | nbargs = 0; |
| 2000 | while ((*cur == ' ') || (*cur == '\t')) |
| 2001 | cur++; |
| 2002 | i = 0; |
| 2003 | while ((*cur != ' ') && (*cur != '\t') && |
| 2004 | (*cur != '\n') && (*cur != '\r')) { |
| 2005 | if (*cur == 0) |
| 2006 | break; |
| 2007 | command[i++] = *cur++; |
| 2008 | } |
| 2009 | command[i] = 0; |
| 2010 | if (i == 0) |
| 2011 | continue; |
| 2012 | nbargs++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2013 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2014 | /* |
| 2015 | * Parse the argument |
| 2016 | */ |
| 2017 | while ((*cur == ' ') || (*cur == '\t')) |
| 2018 | cur++; |
| 2019 | i = 0; |
| 2020 | while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) { |
| 2021 | if (*cur == 0) |
| 2022 | break; |
| 2023 | arg[i++] = *cur++; |
| 2024 | } |
| 2025 | arg[i] = 0; |
| 2026 | if (i != 0) |
| 2027 | nbargs++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2028 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2029 | /* |
| 2030 | * start interpreting the command |
| 2031 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2032 | if (!strcmp(command, "exit")) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2033 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2034 | if (!strcmp(command, "quit")) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2035 | break; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2036 | if (!strcmp(command, "bye")) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2037 | break; |
Daniel Veillard | 5004f42 | 2001-11-08 13:53:05 +0000 | [diff] [blame] | 2038 | if (!strcmp(command, "help")) { |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 2039 | fprintf(stdout, "\tbase display XML base of the node\n"); |
Daniel Veillard | cfa0d81 | 2002-01-17 08:46:58 +0000 | [diff] [blame] | 2040 | fprintf(stdout, "\tsetbase URI change the XML base of the node\n"); |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 2041 | fprintf(stdout, "\tbye leave shell\n"); |
| 2042 | fprintf(stdout, "\tcat [node] display node or current node\n"); |
| 2043 | fprintf(stdout, "\tcd [path] change directory to path or to root\n"); |
| 2044 | fprintf(stdout, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n"); |
| 2045 | fprintf(stdout, "\tdu [path] show the structure of the subtree under path or the current node\n"); |
| 2046 | fprintf(stdout, "\texit leave shell\n"); |
| 2047 | fprintf(stdout, "\thelp display this help\n"); |
| 2048 | fprintf(stdout, "\tfree display memory usage\n"); |
| 2049 | fprintf(stdout, "\tload [name] load a new document with name\n"); |
| 2050 | fprintf(stdout, "\tls [path] list contents of path or the current directory\n"); |
| 2051 | fprintf(stdout, "\tpwd display current working directory\n"); |
| 2052 | fprintf(stdout, "\tquit leave shell\n"); |
| 2053 | fprintf(stdout, "\tsave [name] save this document to name or the original name\n"); |
| 2054 | fprintf(stdout, "\tvalidate check the document for errors\n"); |
| 2055 | fprintf(stdout, "\twrite [name] write the current node to the filename\n"); |
Daniel Veillard | 5004f42 | 2001-11-08 13:53:05 +0000 | [diff] [blame] | 2056 | } else if (!strcmp(command, "validate")) { |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2057 | xmlShellValidate(ctxt, arg, NULL, NULL); |
| 2058 | } else if (!strcmp(command, "load")) { |
| 2059 | xmlShellLoad(ctxt, arg, NULL, NULL); |
| 2060 | } else if (!strcmp(command, "save")) { |
| 2061 | xmlShellSave(ctxt, arg, NULL, NULL); |
| 2062 | } else if (!strcmp(command, "write")) { |
| 2063 | xmlShellWrite(ctxt, arg, NULL, NULL); |
| 2064 | } else if (!strcmp(command, "free")) { |
| 2065 | if (arg[0] == 0) { |
| 2066 | xmlMemShow(stdout, 0); |
| 2067 | } else { |
| 2068 | int len = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2069 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2070 | sscanf(arg, "%d", &len); |
| 2071 | xmlMemShow(stdout, len); |
| 2072 | } |
| 2073 | } else if (!strcmp(command, "pwd")) { |
| 2074 | char dir[500]; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2075 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2076 | if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL)) |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 2077 | fprintf(stdout, "%s\n", dir); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2078 | } else if (!strcmp(command, "du")) { |
| 2079 | xmlShellDu(ctxt, NULL, ctxt->node, NULL); |
| 2080 | } else if (!strcmp(command, "base")) { |
| 2081 | xmlShellBase(ctxt, NULL, ctxt->node, NULL); |
Daniel Veillard | cfa0d81 | 2002-01-17 08:46:58 +0000 | [diff] [blame] | 2082 | } else if (!strcmp(command, "setbase")) { |
| 2083 | xmlShellSetBase(ctxt, arg, ctxt->node, NULL); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2084 | } else if ((!strcmp(command, "ls")) || (!strcmp(command, "dir"))) { |
| 2085 | int dir = (!strcmp(command, "dir")); |
| 2086 | |
| 2087 | if (arg[0] == 0) { |
| 2088 | if (dir) |
| 2089 | xmlShellDir(ctxt, NULL, ctxt->node, NULL); |
| 2090 | else |
| 2091 | xmlShellList(ctxt, NULL, ctxt->node, NULL); |
| 2092 | } else { |
| 2093 | ctxt->pctxt->node = ctxt->node; |
Daniel Veillard | 61d80a2 | 2001-04-27 17:13:01 +0000 | [diff] [blame] | 2094 | #ifdef LIBXML_XPATH_ENABLED |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2095 | ctxt->pctxt->node = ctxt->node; |
| 2096 | list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); |
| 2097 | #else |
| 2098 | list = NULL; |
| 2099 | #endif /* LIBXML_XPATH_ENABLED */ |
| 2100 | if (list != NULL) { |
| 2101 | switch (list->type) { |
| 2102 | case XPATH_UNDEFINED: |
| 2103 | xmlGenericError(xmlGenericErrorContext, |
| 2104 | "%s: no such node\n", arg); |
| 2105 | break; |
| 2106 | case XPATH_NODESET:{ |
| 2107 | int indx; |
| 2108 | |
Daniel Veillard | a6825e8 | 2001-11-07 13:33:59 +0000 | [diff] [blame] | 2109 | if (list->nodesetval == NULL) |
| 2110 | break; |
| 2111 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2112 | for (indx = 0; |
| 2113 | indx < list->nodesetval->nodeNr; |
| 2114 | indx++) { |
| 2115 | if (dir) |
| 2116 | xmlShellDir(ctxt, NULL, |
| 2117 | list->nodesetval-> |
| 2118 | nodeTab[indx], NULL); |
| 2119 | else |
| 2120 | xmlShellList(ctxt, NULL, |
| 2121 | list->nodesetval-> |
| 2122 | nodeTab[indx], NULL); |
| 2123 | } |
| 2124 | break; |
| 2125 | } |
| 2126 | case XPATH_BOOLEAN: |
| 2127 | xmlGenericError(xmlGenericErrorContext, |
| 2128 | "%s is a Boolean\n", arg); |
| 2129 | break; |
| 2130 | case XPATH_NUMBER: |
| 2131 | xmlGenericError(xmlGenericErrorContext, |
| 2132 | "%s is a number\n", arg); |
| 2133 | break; |
| 2134 | case XPATH_STRING: |
| 2135 | xmlGenericError(xmlGenericErrorContext, |
| 2136 | "%s is a string\n", arg); |
| 2137 | break; |
| 2138 | case XPATH_POINT: |
| 2139 | xmlGenericError(xmlGenericErrorContext, |
| 2140 | "%s is a point\n", arg); |
| 2141 | break; |
| 2142 | case XPATH_RANGE: |
| 2143 | xmlGenericError(xmlGenericErrorContext, |
| 2144 | "%s is a range\n", arg); |
| 2145 | break; |
| 2146 | case XPATH_LOCATIONSET: |
| 2147 | xmlGenericError(xmlGenericErrorContext, |
| 2148 | "%s is a range\n", arg); |
| 2149 | break; |
| 2150 | case XPATH_USERS: |
| 2151 | xmlGenericError(xmlGenericErrorContext, |
| 2152 | "%s is user-defined\n", arg); |
| 2153 | break; |
| 2154 | case XPATH_XSLT_TREE: |
| 2155 | xmlGenericError(xmlGenericErrorContext, |
| 2156 | "%s is an XSLT value tree\n", |
| 2157 | arg); |
| 2158 | break; |
| 2159 | } |
| 2160 | #ifdef LIBXML_XPATH_ENABLED |
| 2161 | xmlXPathFreeObject(list); |
Daniel Veillard | 61d80a2 | 2001-04-27 17:13:01 +0000 | [diff] [blame] | 2162 | #endif |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2163 | } else { |
| 2164 | xmlGenericError(xmlGenericErrorContext, |
| 2165 | "%s: no such node\n", arg); |
| 2166 | } |
| 2167 | ctxt->pctxt->node = NULL; |
| 2168 | } |
| 2169 | } else if (!strcmp(command, "cd")) { |
| 2170 | if (arg[0] == 0) { |
| 2171 | ctxt->node = (xmlNodePtr) ctxt->doc; |
| 2172 | } else { |
| 2173 | #ifdef LIBXML_XPATH_ENABLED |
| 2174 | ctxt->pctxt->node = ctxt->node; |
| 2175 | list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); |
| 2176 | #else |
| 2177 | list = NULL; |
| 2178 | #endif /* LIBXML_XPATH_ENABLED */ |
| 2179 | if (list != NULL) { |
| 2180 | switch (list->type) { |
| 2181 | case XPATH_UNDEFINED: |
| 2182 | xmlGenericError(xmlGenericErrorContext, |
| 2183 | "%s: no such node\n", arg); |
| 2184 | break; |
| 2185 | case XPATH_NODESET: |
Daniel Veillard | a6825e8 | 2001-11-07 13:33:59 +0000 | [diff] [blame] | 2186 | if (list->nodesetval != NULL) { |
| 2187 | if (list->nodesetval->nodeNr == 1) { |
| 2188 | ctxt->node = list->nodesetval->nodeTab[0]; |
| 2189 | } else |
| 2190 | xmlGenericError(xmlGenericErrorContext, |
| 2191 | "%s is a %d Node Set\n", |
| 2192 | arg, |
| 2193 | list->nodesetval->nodeNr); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2194 | } else |
| 2195 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | a6825e8 | 2001-11-07 13:33:59 +0000 | [diff] [blame] | 2196 | "%s is an empty Node Set\n", |
| 2197 | arg); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | case XPATH_BOOLEAN: |
| 2200 | xmlGenericError(xmlGenericErrorContext, |
| 2201 | "%s is a Boolean\n", arg); |
| 2202 | break; |
| 2203 | case XPATH_NUMBER: |
| 2204 | xmlGenericError(xmlGenericErrorContext, |
| 2205 | "%s is a number\n", arg); |
| 2206 | break; |
| 2207 | case XPATH_STRING: |
| 2208 | xmlGenericError(xmlGenericErrorContext, |
| 2209 | "%s is a string\n", arg); |
| 2210 | break; |
| 2211 | case XPATH_POINT: |
| 2212 | xmlGenericError(xmlGenericErrorContext, |
| 2213 | "%s is a point\n", arg); |
| 2214 | break; |
| 2215 | case XPATH_RANGE: |
| 2216 | xmlGenericError(xmlGenericErrorContext, |
| 2217 | "%s is a range\n", arg); |
| 2218 | break; |
| 2219 | case XPATH_LOCATIONSET: |
| 2220 | xmlGenericError(xmlGenericErrorContext, |
| 2221 | "%s is a range\n", arg); |
| 2222 | break; |
| 2223 | case XPATH_USERS: |
| 2224 | xmlGenericError(xmlGenericErrorContext, |
| 2225 | "%s is user-defined\n", arg); |
| 2226 | break; |
| 2227 | case XPATH_XSLT_TREE: |
| 2228 | xmlGenericError(xmlGenericErrorContext, |
| 2229 | "%s is an XSLT value tree\n", |
| 2230 | arg); |
| 2231 | break; |
| 2232 | } |
| 2233 | #ifdef LIBXML_XPATH_ENABLED |
| 2234 | xmlXPathFreeObject(list); |
| 2235 | #endif |
| 2236 | } else { |
| 2237 | xmlGenericError(xmlGenericErrorContext, |
| 2238 | "%s: no such node\n", arg); |
| 2239 | } |
| 2240 | ctxt->pctxt->node = NULL; |
| 2241 | } |
| 2242 | } else if (!strcmp(command, "cat")) { |
| 2243 | if (arg[0] == 0) { |
| 2244 | xmlShellCat(ctxt, NULL, ctxt->node, NULL); |
| 2245 | } else { |
| 2246 | ctxt->pctxt->node = ctxt->node; |
| 2247 | #ifdef LIBXML_XPATH_ENABLED |
| 2248 | ctxt->pctxt->node = ctxt->node; |
| 2249 | list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); |
| 2250 | #else |
| 2251 | list = NULL; |
| 2252 | #endif /* LIBXML_XPATH_ENABLED */ |
| 2253 | if (list != NULL) { |
| 2254 | switch (list->type) { |
| 2255 | case XPATH_UNDEFINED: |
| 2256 | xmlGenericError(xmlGenericErrorContext, |
| 2257 | "%s: no such node\n", arg); |
| 2258 | break; |
| 2259 | case XPATH_NODESET:{ |
| 2260 | int indx; |
| 2261 | |
Daniel Veillard | a6825e8 | 2001-11-07 13:33:59 +0000 | [diff] [blame] | 2262 | if (list->nodesetval == NULL) |
| 2263 | break; |
| 2264 | |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2265 | for (indx = 0; |
| 2266 | indx < list->nodesetval->nodeNr; |
| 2267 | indx++) { |
| 2268 | if (i > 0) |
Daniel Veillard | cd337f0 | 2001-11-22 18:20:37 +0000 | [diff] [blame] | 2269 | fprintf(stdout, " -------\n"); |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2270 | xmlShellCat(ctxt, NULL, |
| 2271 | list->nodesetval-> |
| 2272 | nodeTab[indx], NULL); |
| 2273 | } |
| 2274 | break; |
| 2275 | } |
| 2276 | case XPATH_BOOLEAN: |
| 2277 | xmlGenericError(xmlGenericErrorContext, |
| 2278 | "%s is a Boolean\n", arg); |
| 2279 | break; |
| 2280 | case XPATH_NUMBER: |
| 2281 | xmlGenericError(xmlGenericErrorContext, |
| 2282 | "%s is a number\n", arg); |
| 2283 | break; |
| 2284 | case XPATH_STRING: |
| 2285 | xmlGenericError(xmlGenericErrorContext, |
| 2286 | "%s is a string\n", arg); |
| 2287 | break; |
| 2288 | case XPATH_POINT: |
| 2289 | xmlGenericError(xmlGenericErrorContext, |
| 2290 | "%s is a point\n", arg); |
| 2291 | break; |
| 2292 | case XPATH_RANGE: |
| 2293 | xmlGenericError(xmlGenericErrorContext, |
| 2294 | "%s is a range\n", arg); |
| 2295 | break; |
| 2296 | case XPATH_LOCATIONSET: |
| 2297 | xmlGenericError(xmlGenericErrorContext, |
| 2298 | "%s is a range\n", arg); |
| 2299 | break; |
| 2300 | case XPATH_USERS: |
| 2301 | xmlGenericError(xmlGenericErrorContext, |
| 2302 | "%s is user-defined\n", arg); |
| 2303 | break; |
| 2304 | case XPATH_XSLT_TREE: |
| 2305 | xmlGenericError(xmlGenericErrorContext, |
| 2306 | "%s is an XSLT value tree\n", |
| 2307 | arg); |
| 2308 | break; |
| 2309 | } |
| 2310 | #ifdef LIBXML_XPATH_ENABLED |
| 2311 | xmlXPathFreeObject(list); |
| 2312 | #endif |
| 2313 | } else { |
| 2314 | xmlGenericError(xmlGenericErrorContext, |
| 2315 | "%s: no such node\n", arg); |
| 2316 | } |
| 2317 | ctxt->pctxt->node = NULL; |
| 2318 | } |
| 2319 | } else { |
| 2320 | xmlGenericError(xmlGenericErrorContext, |
| 2321 | "Unknown command %s\n", command); |
| 2322 | } |
| 2323 | free(cmdline); /* not xmlFree here ! */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2324 | } |
| 2325 | #ifdef LIBXML_XPATH_ENABLED |
| 2326 | xmlXPathFreeContext(ctxt->pctxt); |
| 2327 | #endif /* LIBXML_XPATH_ENABLED */ |
| 2328 | if (ctxt->loaded) { |
| 2329 | xmlFreeDoc(ctxt->doc); |
| 2330 | } |
Daniel Veillard | b8c9be9 | 2001-07-09 16:01:19 +0000 | [diff] [blame] | 2331 | if (ctxt->filename != NULL) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2332 | xmlFree(ctxt->filename); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2333 | xmlFree(ctxt); |
| 2334 | if (cmdline != NULL) |
Daniel Veillard | 78d1209 | 2001-10-11 09:12:24 +0000 | [diff] [blame] | 2335 | free(cmdline); /* not xmlFree here ! */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | #endif /* LIBXML_DEBUG_ENABLED */ |