blob: 3874b19fbf6992a854d0a8f468353f01c0b500de [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
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 Veillardc5d64342001-06-24 12:13:24 +00007 * Daniel Veillard <daniel@veillard.com>
Owen Taylor3473f882001-02-23 17:55:21 +00008 */
9
Daniel Veillard34ce8be2002-03-18 19:37:11 +000010#define IN_LIBXML
Bjorn Reese70a9da52001-04-21 16:57:29 +000011#include "libxml.h"
Owen Taylor3473f882001-02-23 17:55:21 +000012#ifdef LIBXML_DEBUG_ENABLED
13
Owen Taylor3473f882001-02-23 17:55:21 +000014#include <string.h>
15#ifdef HAVE_STDLIB_H
16#include <stdlib.h>
17#endif
18#ifdef HAVE_STRING_H
19#include <string.h>
20#endif
21#include <libxml/xmlmemory.h>
22#include <libxml/tree.h>
23#include <libxml/parser.h>
Daniel Veillard567e1b42001-08-01 15:53:47 +000024#include <libxml/parserInternals.h>
Owen Taylor3473f882001-02-23 17:55:21 +000025#include <libxml/valid.h>
26#include <libxml/debugXML.h>
27#include <libxml/HTMLtree.h>
28#include <libxml/HTMLparser.h>
29#include <libxml/xmlerror.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000030#include <libxml/globals.h>
Daniel Veillard0ba59232002-02-10 13:20:39 +000031#include <libxml/xpathInternals.h>
Igor Zlatkovicc06bb622003-04-27 15:59:00 +000032#include <libxml/uri.h>
Daniel Veillard522bc602004-02-21 11:53:09 +000033#ifdef LIBXML_SCHEMAS_ENABLED
34#include <libxml/relaxng.h>
35#endif
Owen Taylor3473f882001-02-23 17:55:21 +000036
Daniel Veillardcfa303a2005-08-25 14:03:56 +000037#define DUMP_TEXT_TYPE 1
38
Daniel Veillard22cdb842004-10-04 14:09:17 +000039typedef struct _xmlDebugCtxt xmlDebugCtxt;
40typedef xmlDebugCtxt *xmlDebugCtxtPtr;
41struct _xmlDebugCtxt {
42 FILE *output; /* the output file */
43 char shift[101]; /* used for indenting */
44 int depth; /* current depth */
45 xmlDocPtr doc; /* current document */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +000046 xmlNodePtr node; /* current node */
Daniel Veillard03a53c32004-10-26 16:06:51 +000047 xmlDictPtr dict; /* the doc dictionnary */
Daniel Veillard22cdb842004-10-04 14:09:17 +000048 int check; /* do just checkings */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +000049 int errors; /* number of errors found */
Daniel Veillard03a53c32004-10-26 16:06:51 +000050 int nodict; /* if the document has no dictionnary */
Daniel Veillardcfa303a2005-08-25 14:03:56 +000051 int options; /* options */
Daniel Veillard22cdb842004-10-04 14:09:17 +000052};
53
54static void xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node);
55
56static void
57xmlCtxtDumpInitCtxt(xmlDebugCtxtPtr ctxt)
58{
59 int i;
60
61 ctxt->depth = 0;
62 ctxt->check = 0;
Daniel Veillard8de5c0b2004-10-07 13:14:19 +000063 ctxt->errors = 0;
Daniel Veillard22cdb842004-10-04 14:09:17 +000064 ctxt->output = stdout;
Daniel Veillard03a53c32004-10-26 16:06:51 +000065 ctxt->doc = NULL;
66 ctxt->node = NULL;
67 ctxt->dict = NULL;
Daniel Veillard6927b102004-10-27 17:29:04 +000068 ctxt->nodict = 0;
Daniel Veillardb6580ae2005-08-25 14:18:56 +000069 ctxt->options = 0;
Daniel Veillard22cdb842004-10-04 14:09:17 +000070 for (i = 0; i < 100; i++)
71 ctxt->shift[i] = ' ';
72 ctxt->shift[100] = 0;
73}
74
75static void
William M. Brack9638d4c2004-10-15 18:25:33 +000076xmlCtxtDumpCleanCtxt(xmlDebugCtxtPtr ctxt ATTRIBUTE_UNUSED)
Daniel Veillard76821142004-10-09 20:39:04 +000077{
William M. Brack9638d4c2004-10-15 18:25:33 +000078 /* remove the ATTRIBUTE_UNUSED when this is added */
Daniel Veillard76821142004-10-09 20:39:04 +000079}
80
81/**
Daniel Veillard0d24b112004-10-11 12:28:34 +000082 * xmlNsCheckScope:
83 * @node: the node
84 * @ns: the namespace node
Daniel Veillard76821142004-10-09 20:39:04 +000085 *
Daniel Veillard0d24b112004-10-11 12:28:34 +000086 * Check that a given namespace is in scope on a node.
Daniel Veillard76821142004-10-09 20:39:04 +000087 *
Daniel Veillardf8e3db02012-09-11 13:26:36 +080088 * Returns 1 if in scope, -1 in case of argument error,
Daniel Veillard0d24b112004-10-11 12:28:34 +000089 * -2 if the namespace is not in scope, and -3 if not on
90 * an ancestor node.
Daniel Veillard76821142004-10-09 20:39:04 +000091 */
92static int
Daniel Veillard0d24b112004-10-11 12:28:34 +000093xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns)
Daniel Veillard76821142004-10-09 20:39:04 +000094{
Daniel Veillard0d24b112004-10-11 12:28:34 +000095 xmlNsPtr cur;
Daniel Veillard76821142004-10-09 20:39:04 +000096
Daniel Veillard0d24b112004-10-11 12:28:34 +000097 if ((node == NULL) || (ns == NULL))
98 return(-1);
99
100 if ((node->type != XML_ELEMENT_NODE) &&
101 (node->type != XML_ATTRIBUTE_NODE) &&
102 (node->type != XML_DOCUMENT_NODE) &&
103 (node->type != XML_TEXT_NODE) &&
104 (node->type != XML_HTML_DOCUMENT_NODE) &&
105 (node->type != XML_XINCLUDE_START))
106 return(-2);
107
108 while ((node != NULL) &&
109 ((node->type == XML_ELEMENT_NODE) ||
110 (node->type == XML_ATTRIBUTE_NODE) ||
111 (node->type == XML_TEXT_NODE) ||
112 (node->type == XML_XINCLUDE_START))) {
113 if ((node->type == XML_ELEMENT_NODE) ||
114 (node->type == XML_XINCLUDE_START)) {
115 cur = node->nsDef;
116 while (cur != NULL) {
117 if (cur == ns)
118 return(1);
119 if (xmlStrEqual(cur->prefix, ns->prefix))
120 return(-2);
121 cur = cur->next;
122 }
Daniel Veillard76821142004-10-09 20:39:04 +0000123 }
Daniel Veillard0d24b112004-10-11 12:28:34 +0000124 node = node->parent;
Daniel Veillard76821142004-10-09 20:39:04 +0000125 }
Daniel Veillard0d24b112004-10-11 12:28:34 +0000126 /* the xml namespace may be declared on the document node */
127 if ((node != NULL) &&
128 ((node->type == XML_DOCUMENT_NODE) ||
129 (node->type == XML_HTML_DOCUMENT_NODE))) {
130 xmlNsPtr oldNs = ((xmlDocPtr) node)->oldNs;
131 if (oldNs == ns)
132 return(1);
133 }
134 return(-3);
Daniel Veillard76821142004-10-09 20:39:04 +0000135}
Daniel Veillard76821142004-10-09 20:39:04 +0000136
Daniel Veillard76821142004-10-09 20:39:04 +0000137static void
Daniel Veillard22cdb842004-10-04 14:09:17 +0000138xmlCtxtDumpSpaces(xmlDebugCtxtPtr ctxt)
139{
140 if (ctxt->check)
141 return;
142 if ((ctxt->output != NULL) && (ctxt->depth > 0)) {
143 if (ctxt->depth < 50)
Daniel Veillardbccae2d2009-06-04 11:22:45 +0200144 fprintf(ctxt->output, "%s", &ctxt->shift[100 - 2 * ctxt->depth]);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000145 else
Daniel Veillardbccae2d2009-06-04 11:22:45 +0200146 fprintf(ctxt->output, "%s", ctxt->shift);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000147 }
148}
149
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000150/**
151 * xmlDebugErr:
152 * @ctxt: a debug context
153 * @error: the error code
154 *
155 * Handle a debug error.
156 */
157static void
158xmlDebugErr(xmlDebugCtxtPtr ctxt, int error, const char *msg)
159{
160 ctxt->errors++;
161 __xmlRaiseError(NULL, NULL, NULL,
162 NULL, ctxt->node, XML_FROM_CHECK,
163 error, XML_ERR_ERROR, NULL, 0,
164 NULL, NULL, NULL, 0, 0,
Daniel Veillardbccae2d2009-06-04 11:22:45 +0200165 "%s", msg);
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000166}
167static void
168xmlDebugErr2(xmlDebugCtxtPtr ctxt, int error, const char *msg, int extra)
169{
170 ctxt->errors++;
171 __xmlRaiseError(NULL, NULL, NULL,
172 NULL, ctxt->node, XML_FROM_CHECK,
173 error, XML_ERR_ERROR, NULL, 0,
174 NULL, NULL, NULL, 0, 0,
175 msg, extra);
176}
177static void
Daniel Veillardc6095782004-10-15 14:50:10 +0000178xmlDebugErr3(xmlDebugCtxtPtr ctxt, int error, const char *msg, const char *extra)
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000179{
180 ctxt->errors++;
181 __xmlRaiseError(NULL, NULL, NULL,
182 NULL, ctxt->node, XML_FROM_CHECK,
183 error, XML_ERR_ERROR, NULL, 0,
184 NULL, NULL, NULL, 0, 0,
185 msg, extra);
186}
187
Daniel Veillard0d24b112004-10-11 12:28:34 +0000188/**
189 * xmlCtxtNsCheckScope:
190 * @ctxt: the debugging context
191 * @node: the node
192 * @ns: the namespace node
193 *
194 * Report if a given namespace is is not in scope.
195 */
196static void
197xmlCtxtNsCheckScope(xmlDebugCtxtPtr ctxt, xmlNodePtr node, xmlNsPtr ns)
198{
199 int ret;
200
201 ret = xmlNsCheckScope(node, ns);
202 if (ret == -2) {
203 if (ns->prefix == NULL)
204 xmlDebugErr(ctxt, XML_CHECK_NS_SCOPE,
205 "Reference to default namespace not in scope\n");
206 else
207 xmlDebugErr3(ctxt, XML_CHECK_NS_SCOPE,
208 "Reference to namespace '%s' not in scope\n",
209 (char *) ns->prefix);
210 }
211 if (ret == -3) {
212 if (ns->prefix == NULL)
213 xmlDebugErr(ctxt, XML_CHECK_NS_ANCESTOR,
214 "Reference to default namespace not on ancestor\n");
215 else
216 xmlDebugErr3(ctxt, XML_CHECK_NS_ANCESTOR,
217 "Reference to namespace '%s' not on ancestor\n",
218 (char *) ns->prefix);
219 }
220}
221
Daniel Veillardc6095782004-10-15 14:50:10 +0000222/**
223 * xmlCtxtCheckString:
224 * @ctxt: the debug context
225 * @str: the string
226 *
227 * Do debugging on the string, currently it just checks the UTF-8 content
228 */
229static void
230xmlCtxtCheckString(xmlDebugCtxtPtr ctxt, const xmlChar * str)
231{
232 if (str == NULL) return;
233 if (ctxt->check) {
234 if (!xmlCheckUTF8(str)) {
Daniel Veillard03a53c32004-10-26 16:06:51 +0000235 xmlDebugErr3(ctxt, XML_CHECK_NOT_UTF8,
Daniel Veillardc6095782004-10-15 14:50:10 +0000236 "String is not UTF-8 %s", (const char *) str);
237 }
238 }
239}
240
Daniel Veillard03a53c32004-10-26 16:06:51 +0000241/**
242 * xmlCtxtCheckName:
243 * @ctxt: the debug context
244 * @name: the name
245 *
246 * Do debugging on the name, for example the dictionnary status and
247 * conformance to the Name production.
248 */
249static void
250xmlCtxtCheckName(xmlDebugCtxtPtr ctxt, const xmlChar * name)
251{
252 if (ctxt->check) {
253 if (name == NULL) {
254 xmlDebugErr(ctxt, XML_CHECK_NO_NAME, "Name is NULL");
255 return;
256 }
257 if (xmlValidateName(name, 0)) {
258 xmlDebugErr3(ctxt, XML_CHECK_NOT_NCNAME,
259 "Name is not an NCName '%s'", (const char *) name);
260 }
261 if ((ctxt->dict != NULL) &&
Daniel Veillard023d0ba2009-07-29 11:34:50 +0200262 (!xmlDictOwns(ctxt->dict, name)) &&
263 ((ctxt->doc == NULL) ||
264 ((ctxt->doc->parseFlags & (XML_PARSE_SAX1 | XML_PARSE_NODICT)) == 0))) {
Daniel Veillard03a53c32004-10-26 16:06:51 +0000265 xmlDebugErr3(ctxt, XML_CHECK_OUTSIDE_DICT,
266 "Name is not from the document dictionnary '%s'",
267 (const char *) name);
268 }
269 }
270}
271
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000272static void
273xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) {
Daniel Veillard03a53c32004-10-26 16:06:51 +0000274 xmlDocPtr doc;
275 xmlDictPtr dict;
276
277 doc = node->doc;
278
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000279 if (node->parent == NULL)
280 xmlDebugErr(ctxt, XML_CHECK_NO_PARENT,
281 "Node has no parent\n");
Daniel Veillard03a53c32004-10-26 16:06:51 +0000282 if (node->doc == NULL) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000283 xmlDebugErr(ctxt, XML_CHECK_NO_DOC,
284 "Node has no doc\n");
Daniel Veillard03a53c32004-10-26 16:06:51 +0000285 dict = NULL;
286 } else {
287 dict = doc->dict;
288 if ((dict == NULL) && (ctxt->nodict == 0)) {
Daniel Veillard6927b102004-10-27 17:29:04 +0000289#if 0
290 /* desactivated right now as it raises too many errors */
291 if (doc->type == XML_DOCUMENT_NODE)
292 xmlDebugErr(ctxt, XML_CHECK_NO_DICT,
293 "Document has no dictionnary\n");
294#endif
Daniel Veillard03a53c32004-10-26 16:06:51 +0000295 ctxt->nodict = 1;
296 }
297 if (ctxt->doc == NULL)
298 ctxt->doc = doc;
299
300 if (ctxt->dict == NULL) {
301 ctxt->dict = dict;
302 }
303 }
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000304 if ((node->parent != NULL) && (node->doc != node->parent->doc) &&
305 (!xmlStrEqual(node->name, BAD_CAST "pseudoroot")))
306 xmlDebugErr(ctxt, XML_CHECK_WRONG_DOC,
307 "Node doc differs from parent's one\n");
308 if (node->prev == NULL) {
309 if (node->type == XML_ATTRIBUTE_NODE) {
310 if ((node->parent != NULL) &&
311 (node != (xmlNodePtr) node->parent->properties))
312 xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
313 "Attr has no prev and not first of attr list\n");
Daniel Veillardf8e3db02012-09-11 13:26:36 +0800314
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000315 } else if ((node->parent != NULL) && (node->parent->children != node))
316 xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
317 "Node has no prev and not first of parent list\n");
318 } else {
319 if (node->prev->next != node)
320 xmlDebugErr(ctxt, XML_CHECK_WRONG_PREV,
321 "Node prev->next : back link wrong\n");
322 }
323 if (node->next == NULL) {
324 if ((node->parent != NULL) && (node->type != XML_ATTRIBUTE_NODE) &&
Daniel Veillard97c9ce22008-03-25 16:52:41 +0000325 (node->parent->last != node) &&
326 (node->parent->type == XML_ELEMENT_NODE))
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000327 xmlDebugErr(ctxt, XML_CHECK_NO_NEXT,
328 "Node has no next and not last of parent list\n");
329 } else {
330 if (node->next->prev != node)
331 xmlDebugErr(ctxt, XML_CHECK_WRONG_NEXT,
332 "Node next->prev : forward link wrong\n");
Daniel Veillard0d24b112004-10-11 12:28:34 +0000333 if (node->next->parent != node->parent)
334 xmlDebugErr(ctxt, XML_CHECK_WRONG_PARENT,
335 "Node next->prev : forward link wrong\n");
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000336 }
Daniel Veillard0d24b112004-10-11 12:28:34 +0000337 if (node->type == XML_ELEMENT_NODE) {
338 xmlNsPtr ns;
339
340 ns = node->nsDef;
341 while (ns != NULL) {
342 xmlCtxtNsCheckScope(ctxt, node, ns);
343 ns = ns->next;
344 }
345 if (node->ns != NULL)
346 xmlCtxtNsCheckScope(ctxt, node, node->ns);
347 } else if (node->type == XML_ATTRIBUTE_NODE) {
348 if (node->ns != NULL)
349 xmlCtxtNsCheckScope(ctxt, node, node->ns);
350 }
351
Daniel Veillardc6095782004-10-15 14:50:10 +0000352 if ((node->type != XML_ELEMENT_NODE) &&
William M. Brack9638d4c2004-10-15 18:25:33 +0000353 (node->type != XML_ATTRIBUTE_NODE) &&
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000354 (node->type != XML_ELEMENT_DECL) &&
William M. Brack9638d4c2004-10-15 18:25:33 +0000355 (node->type != XML_ATTRIBUTE_DECL) &&
356 (node->type != XML_DTD_NODE) &&
William M. Brack0357a302005-07-06 17:39:14 +0000357 (node->type != XML_ELEMENT_DECL) &&
William M. Brack9638d4c2004-10-15 18:25:33 +0000358 (node->type != XML_HTML_DOCUMENT_NODE) &&
359 (node->type != XML_DOCUMENT_NODE)) {
Daniel Veillardc6095782004-10-15 14:50:10 +0000360 if (node->content != NULL)
William M. Brack9638d4c2004-10-15 18:25:33 +0000361 xmlCtxtCheckString(ctxt, (const xmlChar *) node->content);
Daniel Veillardc6095782004-10-15 14:50:10 +0000362 }
Daniel Veillard03a53c32004-10-26 16:06:51 +0000363 switch (node->type) {
364 case XML_ELEMENT_NODE:
365 case XML_ATTRIBUTE_NODE:
366 xmlCtxtCheckName(ctxt, node->name);
367 break;
368 case XML_TEXT_NODE:
369 if ((node->name == xmlStringText) ||
370 (node->name == xmlStringTextNoenc))
371 break;
372 /* some case of entity substitution can lead to this */
373 if ((ctxt->dict != NULL) &&
Daniel Veillard6927b102004-10-27 17:29:04 +0000374 (node->name == xmlDictLookup(ctxt->dict, BAD_CAST "nbktext",
375 7)))
Daniel Veillard03a53c32004-10-26 16:06:51 +0000376 break;
377
378 xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
379 "Text node has wrong name '%s'",
380 (const char *) node->name);
381 break;
382 case XML_COMMENT_NODE:
383 if (node->name == xmlStringComment)
384 break;
385 xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
386 "Comment node has wrong name '%s'",
387 (const char *) node->name);
388 break;
389 case XML_PI_NODE:
390 xmlCtxtCheckName(ctxt, node->name);
391 break;
392 case XML_CDATA_SECTION_NODE:
393 if (node->name == NULL)
394 break;
395 xmlDebugErr3(ctxt, XML_CHECK_NAME_NOT_NULL,
396 "CData section has non NULL name '%s'",
397 (const char *) node->name);
398 break;
399 case XML_ENTITY_REF_NODE:
400 case XML_ENTITY_NODE:
401 case XML_DOCUMENT_TYPE_NODE:
402 case XML_DOCUMENT_FRAG_NODE:
403 case XML_NOTATION_NODE:
404 case XML_DTD_NODE:
405 case XML_ELEMENT_DECL:
406 case XML_ATTRIBUTE_DECL:
407 case XML_ENTITY_DECL:
408 case XML_NAMESPACE_DECL:
409 case XML_XINCLUDE_START:
410 case XML_XINCLUDE_END:
411#ifdef LIBXML_DOCB_ENABLED
412 case XML_DOCB_DOCUMENT_NODE:
413#endif
414 case XML_DOCUMENT_NODE:
415 case XML_HTML_DOCUMENT_NODE:
416 break;
417 }
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000418}
419
Daniel Veillard22cdb842004-10-04 14:09:17 +0000420static void
421xmlCtxtDumpString(xmlDebugCtxtPtr ctxt, const xmlChar * str)
422{
423 int i;
424
Daniel Veillardc6095782004-10-15 14:50:10 +0000425 if (ctxt->check) {
Daniel Veillard22cdb842004-10-04 14:09:17 +0000426 return;
Daniel Veillardc6095782004-10-15 14:50:10 +0000427 }
Daniel Veillard22cdb842004-10-04 14:09:17 +0000428 /* TODO: check UTF8 content of the string */
429 if (str == NULL) {
430 fprintf(ctxt->output, "(NULL)");
431 return;
432 }
433 for (i = 0; i < 40; i++)
434 if (str[i] == 0)
435 return;
436 else if (IS_BLANK_CH(str[i]))
437 fputc(' ', ctxt->output);
438 else if (str[i] >= 0x80)
439 fprintf(ctxt->output, "#%X", str[i]);
440 else
441 fputc(str[i], ctxt->output);
442 fprintf(ctxt->output, "...");
443}
444
445static void
446xmlCtxtDumpDtdNode(xmlDebugCtxtPtr ctxt, xmlDtdPtr dtd)
447{
448 xmlCtxtDumpSpaces(ctxt);
449
450 if (dtd == NULL) {
451 if (!ctxt->check)
452 fprintf(ctxt->output, "DTD node is NULL\n");
453 return;
454 }
455
456 if (dtd->type != XML_DTD_NODE) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000457 xmlDebugErr(ctxt, XML_CHECK_NOT_DTD,
458 "Node is not a DTD");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000459 return;
460 }
461 if (!ctxt->check) {
462 if (dtd->name != NULL)
463 fprintf(ctxt->output, "DTD(%s)", (char *) dtd->name);
464 else
465 fprintf(ctxt->output, "DTD");
466 if (dtd->ExternalID != NULL)
467 fprintf(ctxt->output, ", PUBLIC %s", (char *) dtd->ExternalID);
468 if (dtd->SystemID != NULL)
469 fprintf(ctxt->output, ", SYSTEM %s", (char *) dtd->SystemID);
470 fprintf(ctxt->output, "\n");
471 }
472 /*
473 * Do a bit of checking
474 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000475 xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) dtd);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000476}
477
478static void
479xmlCtxtDumpAttrDecl(xmlDebugCtxtPtr ctxt, xmlAttributePtr attr)
480{
481 xmlCtxtDumpSpaces(ctxt);
482
483 if (attr == NULL) {
484 if (!ctxt->check)
485 fprintf(ctxt->output, "Attribute declaration is NULL\n");
486 return;
487 }
488 if (attr->type != XML_ATTRIBUTE_DECL) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000489 xmlDebugErr(ctxt, XML_CHECK_NOT_ATTR_DECL,
490 "Node is not an attribute declaration");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000491 return;
492 }
493 if (attr->name != NULL) {
494 if (!ctxt->check)
495 fprintf(ctxt->output, "ATTRDECL(%s)", (char *) attr->name);
496 } else
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000497 xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
498 "Node attribute declaration has no name");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000499 if (attr->elem != NULL) {
500 if (!ctxt->check)
501 fprintf(ctxt->output, " for %s", (char *) attr->elem);
502 } else
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000503 xmlDebugErr(ctxt, XML_CHECK_NO_ELEM,
504 "Node attribute declaration has no element name");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000505 if (!ctxt->check) {
506 switch (attr->atype) {
507 case XML_ATTRIBUTE_CDATA:
508 fprintf(ctxt->output, " CDATA");
509 break;
510 case XML_ATTRIBUTE_ID:
511 fprintf(ctxt->output, " ID");
512 break;
513 case XML_ATTRIBUTE_IDREF:
514 fprintf(ctxt->output, " IDREF");
515 break;
516 case XML_ATTRIBUTE_IDREFS:
517 fprintf(ctxt->output, " IDREFS");
518 break;
519 case XML_ATTRIBUTE_ENTITY:
520 fprintf(ctxt->output, " ENTITY");
521 break;
522 case XML_ATTRIBUTE_ENTITIES:
523 fprintf(ctxt->output, " ENTITIES");
524 break;
525 case XML_ATTRIBUTE_NMTOKEN:
526 fprintf(ctxt->output, " NMTOKEN");
527 break;
528 case XML_ATTRIBUTE_NMTOKENS:
529 fprintf(ctxt->output, " NMTOKENS");
530 break;
531 case XML_ATTRIBUTE_ENUMERATION:
532 fprintf(ctxt->output, " ENUMERATION");
533 break;
534 case XML_ATTRIBUTE_NOTATION:
535 fprintf(ctxt->output, " NOTATION ");
536 break;
537 }
538 if (attr->tree != NULL) {
539 int indx;
540 xmlEnumerationPtr cur = attr->tree;
541
542 for (indx = 0; indx < 5; indx++) {
543 if (indx != 0)
544 fprintf(ctxt->output, "|%s", (char *) cur->name);
545 else
546 fprintf(ctxt->output, " (%s", (char *) cur->name);
547 cur = cur->next;
548 if (cur == NULL)
549 break;
550 }
551 if (cur == NULL)
552 fprintf(ctxt->output, ")");
553 else
554 fprintf(ctxt->output, "...)");
555 }
556 switch (attr->def) {
557 case XML_ATTRIBUTE_NONE:
558 break;
559 case XML_ATTRIBUTE_REQUIRED:
560 fprintf(ctxt->output, " REQUIRED");
561 break;
562 case XML_ATTRIBUTE_IMPLIED:
563 fprintf(ctxt->output, " IMPLIED");
564 break;
565 case XML_ATTRIBUTE_FIXED:
566 fprintf(ctxt->output, " FIXED");
567 break;
568 }
569 if (attr->defaultValue != NULL) {
570 fprintf(ctxt->output, "\"");
571 xmlCtxtDumpString(ctxt, attr->defaultValue);
572 fprintf(ctxt->output, "\"");
573 }
574 fprintf(ctxt->output, "\n");
575 }
576
577 /*
578 * Do a bit of checking
579 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000580 xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) attr);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000581}
582
583static void
584xmlCtxtDumpElemDecl(xmlDebugCtxtPtr ctxt, xmlElementPtr elem)
585{
586 xmlCtxtDumpSpaces(ctxt);
587
588 if (elem == NULL) {
589 if (!ctxt->check)
590 fprintf(ctxt->output, "Element declaration is NULL\n");
591 return;
592 }
593 if (elem->type != XML_ELEMENT_DECL) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000594 xmlDebugErr(ctxt, XML_CHECK_NOT_ELEM_DECL,
595 "Node is not an element declaration");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000596 return;
597 }
598 if (elem->name != NULL) {
599 if (!ctxt->check) {
600 fprintf(ctxt->output, "ELEMDECL(");
601 xmlCtxtDumpString(ctxt, elem->name);
602 fprintf(ctxt->output, ")");
603 }
604 } else
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000605 xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
606 "Element declaration has no name");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000607 if (!ctxt->check) {
608 switch (elem->etype) {
609 case XML_ELEMENT_TYPE_UNDEFINED:
610 fprintf(ctxt->output, ", UNDEFINED");
611 break;
612 case XML_ELEMENT_TYPE_EMPTY:
613 fprintf(ctxt->output, ", EMPTY");
614 break;
615 case XML_ELEMENT_TYPE_ANY:
616 fprintf(ctxt->output, ", ANY");
617 break;
618 case XML_ELEMENT_TYPE_MIXED:
619 fprintf(ctxt->output, ", MIXED ");
620 break;
621 case XML_ELEMENT_TYPE_ELEMENT:
622 fprintf(ctxt->output, ", MIXED ");
623 break;
624 }
625 if ((elem->type != XML_ELEMENT_NODE) && (elem->content != NULL)) {
626 char buf[5001];
627
628 buf[0] = 0;
629 xmlSnprintfElementContent(buf, 5000, elem->content, 1);
630 buf[5000] = 0;
631 fprintf(ctxt->output, "%s", buf);
632 }
633 fprintf(ctxt->output, "\n");
634 }
635
636 /*
637 * Do a bit of checking
638 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000639 xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) elem);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000640}
641
642static void
643xmlCtxtDumpEntityDecl(xmlDebugCtxtPtr ctxt, xmlEntityPtr ent)
644{
645 xmlCtxtDumpSpaces(ctxt);
646
647 if (ent == NULL) {
648 if (!ctxt->check)
649 fprintf(ctxt->output, "Entity declaration is NULL\n");
650 return;
651 }
652 if (ent->type != XML_ENTITY_DECL) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000653 xmlDebugErr(ctxt, XML_CHECK_NOT_ENTITY_DECL,
654 "Node is not an entity declaration");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000655 return;
656 }
657 if (ent->name != NULL) {
658 if (!ctxt->check) {
659 fprintf(ctxt->output, "ENTITYDECL(");
660 xmlCtxtDumpString(ctxt, ent->name);
661 fprintf(ctxt->output, ")");
662 }
663 } else
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000664 xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
665 "Entity declaration has no name");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000666 if (!ctxt->check) {
667 switch (ent->etype) {
668 case XML_INTERNAL_GENERAL_ENTITY:
669 fprintf(ctxt->output, ", internal\n");
670 break;
671 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
672 fprintf(ctxt->output, ", external parsed\n");
673 break;
674 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
675 fprintf(ctxt->output, ", unparsed\n");
676 break;
677 case XML_INTERNAL_PARAMETER_ENTITY:
678 fprintf(ctxt->output, ", parameter\n");
679 break;
680 case XML_EXTERNAL_PARAMETER_ENTITY:
681 fprintf(ctxt->output, ", external parameter\n");
682 break;
683 case XML_INTERNAL_PREDEFINED_ENTITY:
684 fprintf(ctxt->output, ", predefined\n");
685 break;
686 }
687 if (ent->ExternalID) {
688 xmlCtxtDumpSpaces(ctxt);
689 fprintf(ctxt->output, " ExternalID=%s\n",
690 (char *) ent->ExternalID);
691 }
692 if (ent->SystemID) {
693 xmlCtxtDumpSpaces(ctxt);
694 fprintf(ctxt->output, " SystemID=%s\n",
695 (char *) ent->SystemID);
696 }
697 if (ent->URI != NULL) {
698 xmlCtxtDumpSpaces(ctxt);
699 fprintf(ctxt->output, " URI=%s\n", (char *) ent->URI);
700 }
701 if (ent->content) {
702 xmlCtxtDumpSpaces(ctxt);
703 fprintf(ctxt->output, " content=");
704 xmlCtxtDumpString(ctxt, ent->content);
705 fprintf(ctxt->output, "\n");
706 }
707 }
708
709 /*
710 * Do a bit of checking
711 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000712 xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) ent);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000713}
714
715static void
716xmlCtxtDumpNamespace(xmlDebugCtxtPtr ctxt, xmlNsPtr ns)
717{
718 xmlCtxtDumpSpaces(ctxt);
719
720 if (ns == NULL) {
721 if (!ctxt->check)
722 fprintf(ctxt->output, "namespace node is NULL\n");
723 return;
724 }
725 if (ns->type != XML_NAMESPACE_DECL) {
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000726 xmlDebugErr(ctxt, XML_CHECK_NOT_NS_DECL,
727 "Node is not a namespace declaration");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000728 return;
729 }
730 if (ns->href == NULL) {
731 if (ns->prefix != NULL)
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000732 xmlDebugErr3(ctxt, XML_CHECK_NO_HREF,
733 "Incomplete namespace %s href=NULL\n",
Daniel Veillard22cdb842004-10-04 14:09:17 +0000734 (char *) ns->prefix);
735 else
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000736 xmlDebugErr(ctxt, XML_CHECK_NO_HREF,
737 "Incomplete default namespace href=NULL\n");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000738 } else {
739 if (!ctxt->check) {
740 if (ns->prefix != NULL)
741 fprintf(ctxt->output, "namespace %s href=",
742 (char *) ns->prefix);
743 else
744 fprintf(ctxt->output, "default namespace href=");
745
746 xmlCtxtDumpString(ctxt, ns->href);
747 fprintf(ctxt->output, "\n");
748 }
749 }
750}
751
752static void
753xmlCtxtDumpNamespaceList(xmlDebugCtxtPtr ctxt, xmlNsPtr ns)
754{
755 while (ns != NULL) {
756 xmlCtxtDumpNamespace(ctxt, ns);
757 ns = ns->next;
758 }
759}
760
761static void
762xmlCtxtDumpEntity(xmlDebugCtxtPtr ctxt, xmlEntityPtr ent)
763{
764 xmlCtxtDumpSpaces(ctxt);
765
766 if (ent == NULL) {
767 if (!ctxt->check)
768 fprintf(ctxt->output, "Entity is NULL\n");
769 return;
770 }
771 if (!ctxt->check) {
772 switch (ent->etype) {
773 case XML_INTERNAL_GENERAL_ENTITY:
774 fprintf(ctxt->output, "INTERNAL_GENERAL_ENTITY ");
775 break;
776 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
777 fprintf(ctxt->output, "EXTERNAL_GENERAL_PARSED_ENTITY ");
778 break;
779 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
780 fprintf(ctxt->output, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");
781 break;
782 case XML_INTERNAL_PARAMETER_ENTITY:
783 fprintf(ctxt->output, "INTERNAL_PARAMETER_ENTITY ");
784 break;
785 case XML_EXTERNAL_PARAMETER_ENTITY:
786 fprintf(ctxt->output, "EXTERNAL_PARAMETER_ENTITY ");
787 break;
788 default:
789 fprintf(ctxt->output, "ENTITY_%d ! ", (int) ent->etype);
790 }
791 fprintf(ctxt->output, "%s\n", ent->name);
792 if (ent->ExternalID) {
793 xmlCtxtDumpSpaces(ctxt);
794 fprintf(ctxt->output, "ExternalID=%s\n",
795 (char *) ent->ExternalID);
796 }
797 if (ent->SystemID) {
798 xmlCtxtDumpSpaces(ctxt);
799 fprintf(ctxt->output, "SystemID=%s\n", (char *) ent->SystemID);
800 }
801 if (ent->URI) {
802 xmlCtxtDumpSpaces(ctxt);
803 fprintf(ctxt->output, "URI=%s\n", (char *) ent->URI);
804 }
805 if (ent->content) {
806 xmlCtxtDumpSpaces(ctxt);
807 fprintf(ctxt->output, "content=");
808 xmlCtxtDumpString(ctxt, ent->content);
809 fprintf(ctxt->output, "\n");
810 }
811 }
812}
813
814/**
815 * xmlCtxtDumpAttr:
816 * @output: the FILE * for the output
817 * @attr: the attribute
818 * @depth: the indentation level.
819 *
820 * Dumps debug information for the attribute
821 */
822static void
823xmlCtxtDumpAttr(xmlDebugCtxtPtr ctxt, xmlAttrPtr attr)
824{
825 xmlCtxtDumpSpaces(ctxt);
826
827 if (attr == NULL) {
828 if (!ctxt->check)
829 fprintf(ctxt->output, "Attr is NULL");
830 return;
831 }
832 if (!ctxt->check) {
833 fprintf(ctxt->output, "ATTRIBUTE ");
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000834 xmlCtxtDumpString(ctxt, attr->name);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000835 fprintf(ctxt->output, "\n");
836 if (attr->children != NULL) {
837 ctxt->depth++;
838 xmlCtxtDumpNodeList(ctxt, attr->children);
839 ctxt->depth--;
840 }
841 }
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000842 if (attr->name == NULL)
843 xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
844 "Attribute has no name");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000845
846 /*
847 * Do a bit of checking
848 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000849 xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) attr);
Daniel Veillard22cdb842004-10-04 14:09:17 +0000850}
851
852/**
853 * xmlCtxtDumpAttrList:
854 * @output: the FILE * for the output
855 * @attr: the attribute list
856 * @depth: the indentation level.
857 *
858 * Dumps debug information for the attribute list
859 */
860static void
861xmlCtxtDumpAttrList(xmlDebugCtxtPtr ctxt, xmlAttrPtr attr)
862{
863 while (attr != NULL) {
864 xmlCtxtDumpAttr(ctxt, attr);
865 attr = attr->next;
866 }
867}
868
869/**
870 * xmlCtxtDumpOneNode:
871 * @output: the FILE * for the output
872 * @node: the node
873 * @depth: the indentation level.
874 *
875 * Dumps debug information for the element node, it is not recursive
876 */
877static void
878xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
879{
880 if (node == NULL) {
881 if (!ctxt->check) {
882 xmlCtxtDumpSpaces(ctxt);
883 fprintf(ctxt->output, "node is NULL\n");
884 }
885 return;
886 }
Daniel Veillard8de5c0b2004-10-07 13:14:19 +0000887 ctxt->node = node;
888
Daniel Veillard22cdb842004-10-04 14:09:17 +0000889 switch (node->type) {
890 case XML_ELEMENT_NODE:
891 if (!ctxt->check) {
892 xmlCtxtDumpSpaces(ctxt);
893 fprintf(ctxt->output, "ELEMENT ");
894 if ((node->ns != NULL) && (node->ns->prefix != NULL)) {
895 xmlCtxtDumpString(ctxt, node->ns->prefix);
896 fprintf(ctxt->output, ":");
897 }
898 xmlCtxtDumpString(ctxt, node->name);
899 fprintf(ctxt->output, "\n");
900 }
901 break;
902 case XML_ATTRIBUTE_NODE:
903 if (!ctxt->check)
904 xmlCtxtDumpSpaces(ctxt);
905 fprintf(ctxt->output, "Error, ATTRIBUTE found here\n");
William M. Brack5a9c1fd2004-12-17 21:38:09 +0000906 xmlCtxtGenericNodeCheck(ctxt, node);
907 return;
Daniel Veillard22cdb842004-10-04 14:09:17 +0000908 case XML_TEXT_NODE:
909 if (!ctxt->check) {
910 xmlCtxtDumpSpaces(ctxt);
911 if (node->name == (const xmlChar *) xmlStringTextNoenc)
Daniel Veillard8874b942005-08-25 13:19:21 +0000912 fprintf(ctxt->output, "TEXT no enc");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000913 else
Daniel Veillard8874b942005-08-25 13:19:21 +0000914 fprintf(ctxt->output, "TEXT");
Daniel Veillardcfa303a2005-08-25 14:03:56 +0000915 if (ctxt->options & DUMP_TEXT_TYPE) {
916 if (node->content == (xmlChar *) &(node->properties))
917 fprintf(ctxt->output, " compact\n");
918 else if (xmlDictOwns(ctxt->dict, node->content) == 1)
919 fprintf(ctxt->output, " interned\n");
920 else
921 fprintf(ctxt->output, "\n");
922 } else
Daniel Veillard8874b942005-08-25 13:19:21 +0000923 fprintf(ctxt->output, "\n");
Daniel Veillard22cdb842004-10-04 14:09:17 +0000924 }
925 break;
926 case XML_CDATA_SECTION_NODE:
927 if (!ctxt->check) {
928 xmlCtxtDumpSpaces(ctxt);
929 fprintf(ctxt->output, "CDATA_SECTION\n");
930 }
931 break;
932 case XML_ENTITY_REF_NODE:
933 if (!ctxt->check) {
934 xmlCtxtDumpSpaces(ctxt);
935 fprintf(ctxt->output, "ENTITY_REF(%s)\n",
936 (char *) node->name);
937 }
938 break;
939 case XML_ENTITY_NODE:
940 if (!ctxt->check) {
941 xmlCtxtDumpSpaces(ctxt);
942 fprintf(ctxt->output, "ENTITY\n");
943 }
944 break;
945 case XML_PI_NODE:
946 if (!ctxt->check) {
947 xmlCtxtDumpSpaces(ctxt);
948 fprintf(ctxt->output, "PI %s\n", (char *) node->name);
949 }
950 break;
951 case XML_COMMENT_NODE:
952 if (!ctxt->check) {
953 xmlCtxtDumpSpaces(ctxt);
954 fprintf(ctxt->output, "COMMENT\n");
955 }
956 break;
957 case XML_DOCUMENT_NODE:
958 case XML_HTML_DOCUMENT_NODE:
959 if (!ctxt->check) {
960 xmlCtxtDumpSpaces(ctxt);
961 }
William M. Brack5a9c1fd2004-12-17 21:38:09 +0000962 fprintf(ctxt->output, "Error, DOCUMENT found here\n");
963 xmlCtxtGenericNodeCheck(ctxt, node);
964 return;
Daniel Veillard22cdb842004-10-04 14:09:17 +0000965 case XML_DOCUMENT_TYPE_NODE:
966 if (!ctxt->check) {
967 xmlCtxtDumpSpaces(ctxt);
968 fprintf(ctxt->output, "DOCUMENT_TYPE\n");
969 }
970 break;
971 case XML_DOCUMENT_FRAG_NODE:
972 if (!ctxt->check) {
973 xmlCtxtDumpSpaces(ctxt);
974 fprintf(ctxt->output, "DOCUMENT_FRAG\n");
975 }
976 break;
977 case XML_NOTATION_NODE:
978 if (!ctxt->check) {
979 xmlCtxtDumpSpaces(ctxt);
980 fprintf(ctxt->output, "NOTATION\n");
981 }
982 break;
983 case XML_DTD_NODE:
984 xmlCtxtDumpDtdNode(ctxt, (xmlDtdPtr) node);
985 return;
986 case XML_ELEMENT_DECL:
987 xmlCtxtDumpElemDecl(ctxt, (xmlElementPtr) node);
988 return;
989 case XML_ATTRIBUTE_DECL:
990 xmlCtxtDumpAttrDecl(ctxt, (xmlAttributePtr) node);
991 return;
992 case XML_ENTITY_DECL:
993 xmlCtxtDumpEntityDecl(ctxt, (xmlEntityPtr) node);
994 return;
995 case XML_NAMESPACE_DECL:
996 xmlCtxtDumpNamespace(ctxt, (xmlNsPtr) node);
997 return;
998 case XML_XINCLUDE_START:
999 if (!ctxt->check) {
1000 xmlCtxtDumpSpaces(ctxt);
1001 fprintf(ctxt->output, "INCLUDE START\n");
1002 }
1003 return;
1004 case XML_XINCLUDE_END:
1005 if (!ctxt->check) {
1006 xmlCtxtDumpSpaces(ctxt);
1007 fprintf(ctxt->output, "INCLUDE END\n");
1008 }
1009 return;
1010 default:
1011 if (!ctxt->check)
1012 xmlCtxtDumpSpaces(ctxt);
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001013 xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
1014 "Unknown node type %d\n", node->type);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001015 return;
1016 }
1017 if (node->doc == NULL) {
1018 if (!ctxt->check) {
1019 xmlCtxtDumpSpaces(ctxt);
1020 }
1021 fprintf(ctxt->output, "PBM: doc == NULL !!!\n");
1022 }
1023 ctxt->depth++;
Daniel Veillard8874b942005-08-25 13:19:21 +00001024 if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL))
Daniel Veillard22cdb842004-10-04 14:09:17 +00001025 xmlCtxtDumpNamespaceList(ctxt, node->nsDef);
Daniel Veillard8874b942005-08-25 13:19:21 +00001026 if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL))
Daniel Veillard22cdb842004-10-04 14:09:17 +00001027 xmlCtxtDumpAttrList(ctxt, node->properties);
1028 if (node->type != XML_ENTITY_REF_NODE) {
1029 if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL)) {
1030 if (!ctxt->check) {
1031 xmlCtxtDumpSpaces(ctxt);
1032 fprintf(ctxt->output, "content=");
1033 xmlCtxtDumpString(ctxt, node->content);
1034 fprintf(ctxt->output, "\n");
1035 }
1036 }
1037 } else {
1038 xmlEntityPtr ent;
1039
1040 ent = xmlGetDocEntity(node->doc, node->name);
1041 if (ent != NULL)
1042 xmlCtxtDumpEntity(ctxt, ent);
1043 }
1044 ctxt->depth--;
1045
1046 /*
1047 * Do a bit of checking
1048 */
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001049 xmlCtxtGenericNodeCheck(ctxt, node);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001050}
1051
1052/**
1053 * xmlCtxtDumpNode:
1054 * @output: the FILE * for the output
1055 * @node: the node
1056 * @depth: the indentation level.
1057 *
1058 * Dumps debug information for the element node, it is recursive
1059 */
1060static void
1061xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
1062{
1063 if (node == NULL) {
1064 if (!ctxt->check) {
1065 xmlCtxtDumpSpaces(ctxt);
1066 fprintf(ctxt->output, "node is NULL\n");
1067 }
1068 return;
1069 }
1070 xmlCtxtDumpOneNode(ctxt, node);
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001071 if ((node->type != XML_NAMESPACE_DECL) &&
Daniel Veillard7837dd82005-09-06 22:16:57 +00001072 (node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
Daniel Veillard22cdb842004-10-04 14:09:17 +00001073 ctxt->depth++;
1074 xmlCtxtDumpNodeList(ctxt, node->children);
1075 ctxt->depth--;
1076 }
1077}
1078
1079/**
1080 * xmlCtxtDumpNodeList:
1081 * @output: the FILE * for the output
1082 * @node: the node list
1083 * @depth: the indentation level.
1084 *
1085 * Dumps debug information for the list of element node, it is recursive
1086 */
1087static void
1088xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
1089{
1090 while (node != NULL) {
1091 xmlCtxtDumpNode(ctxt, node);
1092 node = node->next;
1093 }
1094}
1095
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001096static void
1097xmlCtxtDumpDocHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
1098{
1099 if (doc == NULL) {
1100 if (!ctxt->check)
1101 fprintf(ctxt->output, "DOCUMENT == NULL !\n");
1102 return;
1103 }
1104 ctxt->node = (xmlNodePtr) doc;
1105
1106 switch (doc->type) {
1107 case XML_ELEMENT_NODE:
1108 xmlDebugErr(ctxt, XML_CHECK_FOUND_ELEMENT,
1109 "Misplaced ELEMENT node\n");
1110 break;
1111 case XML_ATTRIBUTE_NODE:
1112 xmlDebugErr(ctxt, XML_CHECK_FOUND_ATTRIBUTE,
1113 "Misplaced ATTRIBUTE node\n");
1114 break;
1115 case XML_TEXT_NODE:
1116 xmlDebugErr(ctxt, XML_CHECK_FOUND_TEXT,
1117 "Misplaced TEXT node\n");
1118 break;
1119 case XML_CDATA_SECTION_NODE:
1120 xmlDebugErr(ctxt, XML_CHECK_FOUND_CDATA,
1121 "Misplaced CDATA node\n");
1122 break;
1123 case XML_ENTITY_REF_NODE:
1124 xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITYREF,
1125 "Misplaced ENTITYREF node\n");
1126 break;
1127 case XML_ENTITY_NODE:
1128 xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITY,
1129 "Misplaced ENTITY node\n");
1130 break;
1131 case XML_PI_NODE:
1132 xmlDebugErr(ctxt, XML_CHECK_FOUND_PI,
1133 "Misplaced PI node\n");
1134 break;
1135 case XML_COMMENT_NODE:
1136 xmlDebugErr(ctxt, XML_CHECK_FOUND_COMMENT,
1137 "Misplaced COMMENT node\n");
1138 break;
1139 case XML_DOCUMENT_NODE:
1140 if (!ctxt->check)
1141 fprintf(ctxt->output, "DOCUMENT\n");
1142 break;
1143 case XML_HTML_DOCUMENT_NODE:
1144 if (!ctxt->check)
1145 fprintf(ctxt->output, "HTML DOCUMENT\n");
1146 break;
1147 case XML_DOCUMENT_TYPE_NODE:
1148 xmlDebugErr(ctxt, XML_CHECK_FOUND_DOCTYPE,
1149 "Misplaced DOCTYPE node\n");
1150 break;
1151 case XML_DOCUMENT_FRAG_NODE:
1152 xmlDebugErr(ctxt, XML_CHECK_FOUND_FRAGMENT,
1153 "Misplaced FRAGMENT node\n");
1154 break;
1155 case XML_NOTATION_NODE:
1156 xmlDebugErr(ctxt, XML_CHECK_FOUND_NOTATION,
1157 "Misplaced NOTATION node\n");
1158 break;
1159 default:
1160 xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
1161 "Unknown node type %d\n", doc->type);
1162 }
1163}
Daniel Veillard22cdb842004-10-04 14:09:17 +00001164
1165/**
1166 * xmlCtxtDumpDocumentHead:
1167 * @output: the FILE * for the output
1168 * @doc: the document
1169 *
1170 * Dumps debug information cncerning the document, not recursive
1171 */
1172static void
1173xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
1174{
Daniel Veillarda82b1822004-11-08 16:24:57 +00001175 if (doc == NULL) return;
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001176 xmlCtxtDumpDocHead(ctxt, doc);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001177 if (!ctxt->check) {
1178 if (doc->name != NULL) {
1179 fprintf(ctxt->output, "name=");
1180 xmlCtxtDumpString(ctxt, BAD_CAST doc->name);
1181 fprintf(ctxt->output, "\n");
1182 }
1183 if (doc->version != NULL) {
1184 fprintf(ctxt->output, "version=");
1185 xmlCtxtDumpString(ctxt, doc->version);
1186 fprintf(ctxt->output, "\n");
1187 }
1188 if (doc->encoding != NULL) {
1189 fprintf(ctxt->output, "encoding=");
1190 xmlCtxtDumpString(ctxt, doc->encoding);
1191 fprintf(ctxt->output, "\n");
1192 }
1193 if (doc->URL != NULL) {
1194 fprintf(ctxt->output, "URL=");
1195 xmlCtxtDumpString(ctxt, doc->URL);
1196 fprintf(ctxt->output, "\n");
1197 }
1198 if (doc->standalone)
1199 fprintf(ctxt->output, "standalone=true\n");
1200 }
1201 if (doc->oldNs != NULL)
1202 xmlCtxtDumpNamespaceList(ctxt, doc->oldNs);
1203}
1204
1205/**
1206 * xmlCtxtDumpDocument:
1207 * @output: the FILE * for the output
1208 * @doc: the document
1209 *
1210 * Dumps debug information for the document, it's recursive
1211 */
1212static void
1213xmlCtxtDumpDocument(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
1214{
1215 if (doc == NULL) {
1216 if (!ctxt->check)
1217 fprintf(ctxt->output, "DOCUMENT == NULL !\n");
1218 return;
1219 }
1220 xmlCtxtDumpDocumentHead(ctxt, doc);
1221 if (((doc->type == XML_DOCUMENT_NODE) ||
1222 (doc->type == XML_HTML_DOCUMENT_NODE))
1223 && (doc->children != NULL)) {
1224 ctxt->depth++;
1225 xmlCtxtDumpNodeList(ctxt, doc->children);
1226 ctxt->depth--;
1227 }
1228}
1229
1230static void
1231xmlCtxtDumpEntityCallback(xmlEntityPtr cur, xmlDebugCtxtPtr ctxt)
1232{
1233 if (cur == NULL) {
1234 if (!ctxt->check)
1235 fprintf(ctxt->output, "Entity is NULL");
1236 return;
1237 }
1238 if (!ctxt->check) {
1239 fprintf(ctxt->output, "%s : ", (char *) cur->name);
1240 switch (cur->etype) {
1241 case XML_INTERNAL_GENERAL_ENTITY:
1242 fprintf(ctxt->output, "INTERNAL GENERAL, ");
1243 break;
1244 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
1245 fprintf(ctxt->output, "EXTERNAL PARSED, ");
1246 break;
1247 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
1248 fprintf(ctxt->output, "EXTERNAL UNPARSED, ");
1249 break;
1250 case XML_INTERNAL_PARAMETER_ENTITY:
1251 fprintf(ctxt->output, "INTERNAL PARAMETER, ");
1252 break;
1253 case XML_EXTERNAL_PARAMETER_ENTITY:
1254 fprintf(ctxt->output, "EXTERNAL PARAMETER, ");
1255 break;
1256 default:
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001257 xmlDebugErr2(ctxt, XML_CHECK_ENTITY_TYPE,
1258 "Unknown entity type %d\n", cur->etype);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001259 }
1260 if (cur->ExternalID != NULL)
1261 fprintf(ctxt->output, "ID \"%s\"", (char *) cur->ExternalID);
1262 if (cur->SystemID != NULL)
1263 fprintf(ctxt->output, "SYSTEM \"%s\"", (char *) cur->SystemID);
1264 if (cur->orig != NULL)
1265 fprintf(ctxt->output, "\n orig \"%s\"", (char *) cur->orig);
1266 if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL))
1267 fprintf(ctxt->output, "\n content \"%s\"",
1268 (char *) cur->content);
1269 fprintf(ctxt->output, "\n");
1270 }
1271}
1272
1273/**
1274 * xmlCtxtDumpEntities:
1275 * @output: the FILE * for the output
1276 * @doc: the document
1277 *
1278 * Dumps debug information for all the entities in use by the document
1279 */
1280static void
1281xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
1282{
Daniel Veillarda82b1822004-11-08 16:24:57 +00001283 if (doc == NULL) return;
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001284 xmlCtxtDumpDocHead(ctxt, doc);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001285 if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
1286 xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
1287 doc->intSubset->entities;
1288
1289 if (!ctxt->check)
1290 fprintf(ctxt->output, "Entities in internal subset\n");
1291 xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
1292 ctxt);
1293 } else
1294 fprintf(ctxt->output, "No entities in internal subset\n");
1295 if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
1296 xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
1297 doc->extSubset->entities;
1298
1299 if (!ctxt->check)
1300 fprintf(ctxt->output, "Entities in external subset\n");
1301 xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
1302 ctxt);
1303 } else if (!ctxt->check)
1304 fprintf(ctxt->output, "No entities in external subset\n");
1305}
1306
1307/**
1308 * xmlCtxtDumpDTD:
1309 * @output: the FILE * for the output
1310 * @dtd: the DTD
1311 *
1312 * Dumps debug information for the DTD
1313 */
1314static void
1315xmlCtxtDumpDTD(xmlDebugCtxtPtr ctxt, xmlDtdPtr dtd)
1316{
1317 if (dtd == NULL) {
1318 if (!ctxt->check)
1319 fprintf(ctxt->output, "DTD is NULL\n");
1320 return;
1321 }
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001322 xmlCtxtDumpDtdNode(ctxt, dtd);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001323 if (dtd->children == NULL)
1324 fprintf(ctxt->output, " DTD is empty\n");
1325 else {
1326 ctxt->depth++;
1327 xmlCtxtDumpNodeList(ctxt, dtd->children);
1328 ctxt->depth--;
1329 }
1330}
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001331
Daniel Veillard22cdb842004-10-04 14:09:17 +00001332/************************************************************************
1333 * *
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001334 * Public entry points for dump *
Daniel Veillard22cdb842004-10-04 14:09:17 +00001335 * *
1336 ************************************************************************/
1337
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001338/**
1339 * xmlDebugDumpString:
1340 * @output: the FILE * for the output
1341 * @str: the string
1342 *
1343 * Dumps informations about the string, shorten it if necessary
1344 */
1345void
1346xmlDebugDumpString(FILE * output, const xmlChar * str)
1347{
Owen Taylor3473f882001-02-23 17:55:21 +00001348 int i;
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001349
Daniel Veillard7db38712002-02-07 16:39:11 +00001350 if (output == NULL)
1351 output = stdout;
Owen Taylor3473f882001-02-23 17:55:21 +00001352 if (str == NULL) {
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001353 fprintf(output, "(NULL)");
1354 return;
Owen Taylor3473f882001-02-23 17:55:21 +00001355 }
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001356 for (i = 0; i < 40; i++)
1357 if (str[i] == 0)
1358 return;
William M. Brack76e95df2003-10-18 16:20:14 +00001359 else if (IS_BLANK_CH(str[i]))
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001360 fputc(' ', output);
1361 else if (str[i] >= 0x80)
1362 fprintf(output, "#%X", str[i]);
1363 else
1364 fputc(str[i], output);
Owen Taylor3473f882001-02-23 17:55:21 +00001365 fprintf(output, "...");
1366}
1367
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001368/**
1369 * xmlDebugDumpAttr:
1370 * @output: the FILE * for the output
1371 * @attr: the attribute
1372 * @depth: the indentation level.
1373 *
1374 * Dumps debug information for the attribute
1375 */
1376void
1377xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
Daniel Veillard22cdb842004-10-04 14:09:17 +00001378 xmlDebugCtxt ctxt;
Owen Taylor3473f882001-02-23 17:55:21 +00001379
Daniel Veillarda82b1822004-11-08 16:24:57 +00001380 if (output == NULL) return;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001381 xmlCtxtDumpInitCtxt(&ctxt);
1382 ctxt.output = output;
1383 ctxt.depth = depth;
1384 xmlCtxtDumpAttr(&ctxt, attr);
Daniel Veillard76821142004-10-09 20:39:04 +00001385 xmlCtxtDumpCleanCtxt(&ctxt);
Daniel Veillard22cdb842004-10-04 14:09:17 +00001386}
Owen Taylor3473f882001-02-23 17:55:21 +00001387
Owen Taylor3473f882001-02-23 17:55:21 +00001388
Daniel Veillard22cdb842004-10-04 14:09:17 +00001389/**
1390 * xmlDebugDumpEntities:
1391 * @output: the FILE * for the output
1392 * @doc: the document
1393 *
1394 * Dumps debug information for all the entities in use by the document
1395 */
1396void
1397xmlDebugDumpEntities(FILE * output, xmlDocPtr doc)
1398{
1399 xmlDebugCtxt ctxt;
1400
Daniel Veillarda82b1822004-11-08 16:24:57 +00001401 if (output == NULL) return;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001402 xmlCtxtDumpInitCtxt(&ctxt);
1403 ctxt.output = output;
1404 xmlCtxtDumpEntities(&ctxt, doc);
Daniel Veillard76821142004-10-09 20:39:04 +00001405 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001406}
1407
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001408/**
1409 * xmlDebugDumpAttrList:
1410 * @output: the FILE * for the output
1411 * @attr: the attribute list
1412 * @depth: the indentation level.
1413 *
1414 * Dumps debug information for the attribute list
1415 */
1416void
1417xmlDebugDumpAttrList(FILE * output, xmlAttrPtr attr, int depth)
1418{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001419 xmlDebugCtxt ctxt;
1420
Daniel Veillarda82b1822004-11-08 16:24:57 +00001421 if (output == NULL) return;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001422 xmlCtxtDumpInitCtxt(&ctxt);
1423 ctxt.output = output;
1424 ctxt.depth = depth;
1425 xmlCtxtDumpAttrList(&ctxt, attr);
Daniel Veillard76821142004-10-09 20:39:04 +00001426 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001427}
1428
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001429/**
1430 * xmlDebugDumpOneNode:
1431 * @output: the FILE * for the output
1432 * @node: the node
1433 * @depth: the indentation level.
1434 *
1435 * Dumps debug information for the element node, it is not recursive
1436 */
1437void
1438xmlDebugDumpOneNode(FILE * output, xmlNodePtr node, int depth)
1439{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001440 xmlDebugCtxt ctxt;
Owen Taylor3473f882001-02-23 17:55:21 +00001441
Daniel Veillarda82b1822004-11-08 16:24:57 +00001442 if (output == NULL) return;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001443 xmlCtxtDumpInitCtxt(&ctxt);
1444 ctxt.output = output;
1445 ctxt.depth = depth;
1446 xmlCtxtDumpOneNode(&ctxt, node);
Daniel Veillard76821142004-10-09 20:39:04 +00001447 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001448}
1449
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001450/**
1451 * xmlDebugDumpNode:
1452 * @output: the FILE * for the output
1453 * @node: the node
1454 * @depth: the indentation level.
1455 *
1456 * Dumps debug information for the element node, it is recursive
1457 */
1458void
1459xmlDebugDumpNode(FILE * output, xmlNodePtr node, int depth)
1460{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001461 xmlDebugCtxt ctxt;
1462
Daniel Veillard7db38712002-02-07 16:39:11 +00001463 if (output == NULL)
1464 output = stdout;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001465 xmlCtxtDumpInitCtxt(&ctxt);
1466 ctxt.output = output;
1467 ctxt.depth = depth;
1468 xmlCtxtDumpNode(&ctxt, node);
Daniel Veillard76821142004-10-09 20:39:04 +00001469 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001470}
1471
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001472/**
1473 * xmlDebugDumpNodeList:
1474 * @output: the FILE * for the output
1475 * @node: the node list
1476 * @depth: the indentation level.
1477 *
1478 * Dumps debug information for the list of element node, it is recursive
1479 */
1480void
1481xmlDebugDumpNodeList(FILE * output, xmlNodePtr node, int depth)
1482{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001483 xmlDebugCtxt ctxt;
1484
Daniel Veillard7db38712002-02-07 16:39:11 +00001485 if (output == NULL)
1486 output = stdout;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001487 xmlCtxtDumpInitCtxt(&ctxt);
1488 ctxt.output = output;
1489 ctxt.depth = depth;
1490 xmlCtxtDumpNodeList(&ctxt, node);
Daniel Veillard76821142004-10-09 20:39:04 +00001491 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001492}
1493
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001494/**
1495 * xmlDebugDumpDocumentHead:
1496 * @output: the FILE * for the output
1497 * @doc: the document
1498 *
1499 * Dumps debug information cncerning the document, not recursive
1500 */
1501void
1502xmlDebugDumpDocumentHead(FILE * output, xmlDocPtr doc)
1503{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001504 xmlDebugCtxt ctxt;
Owen Taylor3473f882001-02-23 17:55:21 +00001505
Daniel Veillard22cdb842004-10-04 14:09:17 +00001506 if (output == NULL)
1507 output = stdout;
1508 xmlCtxtDumpInitCtxt(&ctxt);
Daniel Veillardcfa303a2005-08-25 14:03:56 +00001509 ctxt.options |= DUMP_TEXT_TYPE;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001510 ctxt.output = output;
1511 xmlCtxtDumpDocumentHead(&ctxt, doc);
Daniel Veillard76821142004-10-09 20:39:04 +00001512 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001513}
1514
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001515/**
1516 * xmlDebugDumpDocument:
1517 * @output: the FILE * for the output
1518 * @doc: the document
1519 *
1520 * Dumps debug information for the document, it's recursive
1521 */
1522void
1523xmlDebugDumpDocument(FILE * output, xmlDocPtr doc)
1524{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001525 xmlDebugCtxt ctxt;
1526
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001527 if (output == NULL)
Daniel Veillard22cdb842004-10-04 14:09:17 +00001528 output = stdout;
1529 xmlCtxtDumpInitCtxt(&ctxt);
Daniel Veillardcfa303a2005-08-25 14:03:56 +00001530 ctxt.options |= DUMP_TEXT_TYPE;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001531 ctxt.output = output;
1532 xmlCtxtDumpDocument(&ctxt, doc);
Daniel Veillard76821142004-10-09 20:39:04 +00001533 xmlCtxtDumpCleanCtxt(&ctxt);
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001534}
Owen Taylor3473f882001-02-23 17:55:21 +00001535
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001536/**
1537 * xmlDebugDumpDTD:
1538 * @output: the FILE * for the output
1539 * @dtd: the DTD
1540 *
1541 * Dumps debug information for the DTD
1542 */
1543void
1544xmlDebugDumpDTD(FILE * output, xmlDtdPtr dtd)
1545{
Daniel Veillard22cdb842004-10-04 14:09:17 +00001546 xmlDebugCtxt ctxt;
1547
Daniel Veillard7db38712002-02-07 16:39:11 +00001548 if (output == NULL)
1549 output = stdout;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001550 xmlCtxtDumpInitCtxt(&ctxt);
Daniel Veillardcfa303a2005-08-25 14:03:56 +00001551 ctxt.options |= DUMP_TEXT_TYPE;
Daniel Veillard22cdb842004-10-04 14:09:17 +00001552 ctxt.output = output;
1553 xmlCtxtDumpDTD(&ctxt, dtd);
Daniel Veillard76821142004-10-09 20:39:04 +00001554 xmlCtxtDumpCleanCtxt(&ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00001555}
1556
Daniel Veillard22cdb842004-10-04 14:09:17 +00001557/************************************************************************
1558 * *
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001559 * Public entry points for checkings *
1560 * *
1561 ************************************************************************/
1562
1563/**
1564 * xmlDebugCheckDocument:
1565 * @output: the FILE * for the output
1566 * @doc: the document
1567 *
1568 * Check the document for potential content problems, and output
1569 * the errors to @output
1570 *
1571 * Returns the number of errors found
1572 */
1573int
1574xmlDebugCheckDocument(FILE * output, xmlDocPtr doc)
1575{
1576 xmlDebugCtxt ctxt;
1577
1578 if (output == NULL)
1579 output = stdout;
1580 xmlCtxtDumpInitCtxt(&ctxt);
1581 ctxt.output = output;
1582 ctxt.check = 1;
1583 xmlCtxtDumpDocument(&ctxt, doc);
Daniel Veillard76821142004-10-09 20:39:04 +00001584 xmlCtxtDumpCleanCtxt(&ctxt);
Daniel Veillard8de5c0b2004-10-07 13:14:19 +00001585 return(ctxt.errors);
1586}
1587
1588/************************************************************************
1589 * *
Daniel Veillard22cdb842004-10-04 14:09:17 +00001590 * Helpers for Shell *
1591 * *
1592 ************************************************************************/
Owen Taylor3473f882001-02-23 17:55:21 +00001593
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001594/**
1595 * xmlLsCountNode:
1596 * @node: the node to count
1597 *
1598 * Count the children of @node.
1599 *
1600 * Returns the number of children of @node.
1601 */
1602int
1603xmlLsCountNode(xmlNodePtr node) {
Owen Taylor3473f882001-02-23 17:55:21 +00001604 int ret = 0;
1605 xmlNodePtr list = NULL;
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001606
Daniel Veillard5e926fa2002-01-22 21:44:25 +00001607 if (node == NULL)
1608 return(0);
Owen Taylor3473f882001-02-23 17:55:21 +00001609
1610 switch (node->type) {
1611 case XML_ELEMENT_NODE:
1612 list = node->children;
1613 break;
1614 case XML_DOCUMENT_NODE:
1615 case XML_HTML_DOCUMENT_NODE:
Daniel Veillardeae522a2001-04-23 13:41:34 +00001616#ifdef LIBXML_DOCB_ENABLED
1617 case XML_DOCB_DOCUMENT_NODE:
Owen Taylor3473f882001-02-23 17:55:21 +00001618#endif
1619 list = ((xmlDocPtr) node)->children;
1620 break;
1621 case XML_ATTRIBUTE_NODE:
1622 list = ((xmlAttrPtr) node)->children;
1623 break;
1624 case XML_TEXT_NODE:
1625 case XML_CDATA_SECTION_NODE:
1626 case XML_PI_NODE:
1627 case XML_COMMENT_NODE:
1628 if (node->content != NULL) {
Owen Taylor3473f882001-02-23 17:55:21 +00001629 ret = xmlStrlen(node->content);
Owen Taylor3473f882001-02-23 17:55:21 +00001630 }
1631 break;
1632 case XML_ENTITY_REF_NODE:
1633 case XML_DOCUMENT_TYPE_NODE:
1634 case XML_ENTITY_NODE:
1635 case XML_DOCUMENT_FRAG_NODE:
1636 case XML_NOTATION_NODE:
1637 case XML_DTD_NODE:
1638 case XML_ELEMENT_DECL:
1639 case XML_ATTRIBUTE_DECL:
1640 case XML_ENTITY_DECL:
1641 case XML_NAMESPACE_DECL:
1642 case XML_XINCLUDE_START:
1643 case XML_XINCLUDE_END:
1644 ret = 1;
1645 break;
1646 }
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001647 for (;list != NULL;ret++)
Owen Taylor3473f882001-02-23 17:55:21 +00001648 list = list->next;
1649 return(ret);
1650}
1651
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001652/**
1653 * xmlLsOneNode:
1654 * @output: the FILE * for the output
1655 * @node: the node to dump
1656 *
1657 * Dump to @output the type and name of @node.
1658 */
Daniel Veillard78d12092001-10-11 09:12:24 +00001659void
Daniel Veillard5e2dace2001-07-18 19:30:27 +00001660xmlLsOneNode(FILE *output, xmlNodePtr node) {
Daniel Veillarda82b1822004-11-08 16:24:57 +00001661 if (output == NULL) return;
Daniel Veillard5e926fa2002-01-22 21:44:25 +00001662 if (node == NULL) {
1663 fprintf(output, "NULL\n");
1664 return;
1665 }
Owen Taylor3473f882001-02-23 17:55:21 +00001666 switch (node->type) {
1667 case XML_ELEMENT_NODE:
1668 fprintf(output, "-");
1669 break;
1670 case XML_ATTRIBUTE_NODE:
1671 fprintf(output, "a");
1672 break;
1673 case XML_TEXT_NODE:
1674 fprintf(output, "t");
1675 break;
1676 case XML_CDATA_SECTION_NODE:
Daniel Veillard75be0132002-03-13 10:03:35 +00001677 fprintf(output, "C");
Owen Taylor3473f882001-02-23 17:55:21 +00001678 break;
1679 case XML_ENTITY_REF_NODE:
1680 fprintf(output, "e");
1681 break;
1682 case XML_ENTITY_NODE:
1683 fprintf(output, "E");
1684 break;
1685 case XML_PI_NODE:
1686 fprintf(output, "p");
1687 break;
1688 case XML_COMMENT_NODE:
1689 fprintf(output, "c");
1690 break;
1691 case XML_DOCUMENT_NODE:
1692 fprintf(output, "d");
1693 break;
1694 case XML_HTML_DOCUMENT_NODE:
1695 fprintf(output, "h");
1696 break;
1697 case XML_DOCUMENT_TYPE_NODE:
1698 fprintf(output, "T");
1699 break;
1700 case XML_DOCUMENT_FRAG_NODE:
1701 fprintf(output, "F");
1702 break;
1703 case XML_NOTATION_NODE:
1704 fprintf(output, "N");
1705 break;
Daniel Veillarde6a55192002-01-14 17:11:53 +00001706 case XML_NAMESPACE_DECL:
1707 fprintf(output, "n");
1708 break;
Owen Taylor3473f882001-02-23 17:55:21 +00001709 default:
1710 fprintf(output, "?");
1711 }
Daniel Veillarde6a55192002-01-14 17:11:53 +00001712 if (node->type != XML_NAMESPACE_DECL) {
1713 if (node->properties != NULL)
1714 fprintf(output, "a");
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001715 else
Daniel Veillarde6a55192002-01-14 17:11:53 +00001716 fprintf(output, "-");
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001717 if (node->nsDef != NULL)
Daniel Veillarde6a55192002-01-14 17:11:53 +00001718 fprintf(output, "n");
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001719 else
Daniel Veillarde6a55192002-01-14 17:11:53 +00001720 fprintf(output, "-");
1721 }
Owen Taylor3473f882001-02-23 17:55:21 +00001722
1723 fprintf(output, " %8d ", xmlLsCountNode(node));
1724
1725 switch (node->type) {
1726 case XML_ELEMENT_NODE:
Ryan40db1ee2012-05-07 17:04:04 +08001727 if (node->name != NULL) {
1728 if ((node->ns != NULL) && (node->ns->prefix != NULL))
1729 fprintf(output, "%s:", node->ns->prefix);
Daniel Veillard580ced82003-03-21 21:22:48 +00001730 fprintf(output, "%s", (const char *) node->name);
Ryan40db1ee2012-05-07 17:04:04 +08001731 }
Owen Taylor3473f882001-02-23 17:55:21 +00001732 break;
1733 case XML_ATTRIBUTE_NODE:
1734 if (node->name != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00001735 fprintf(output, "%s", (const char *) node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00001736 break;
1737 case XML_TEXT_NODE:
1738 if (node->content != NULL) {
Owen Taylor3473f882001-02-23 17:55:21 +00001739 xmlDebugDumpString(output, node->content);
Owen Taylor3473f882001-02-23 17:55:21 +00001740 }
1741 break;
1742 case XML_CDATA_SECTION_NODE:
1743 break;
1744 case XML_ENTITY_REF_NODE:
1745 if (node->name != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00001746 fprintf(output, "%s", (const char *) node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00001747 break;
1748 case XML_ENTITY_NODE:
1749 if (node->name != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00001750 fprintf(output, "%s", (const char *) node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00001751 break;
1752 case XML_PI_NODE:
1753 if (node->name != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00001754 fprintf(output, "%s", (const char *) node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00001755 break;
1756 case XML_COMMENT_NODE:
1757 break;
1758 case XML_DOCUMENT_NODE:
1759 break;
1760 case XML_HTML_DOCUMENT_NODE:
1761 break;
1762 case XML_DOCUMENT_TYPE_NODE:
1763 break;
1764 case XML_DOCUMENT_FRAG_NODE:
1765 break;
1766 case XML_NOTATION_NODE:
1767 break;
Daniel Veillarde6a55192002-01-14 17:11:53 +00001768 case XML_NAMESPACE_DECL: {
1769 xmlNsPtr ns = (xmlNsPtr) node;
1770
1771 if (ns->prefix == NULL)
William M. Brack13dfa872004-09-18 04:52:08 +00001772 fprintf(output, "default -> %s", (char *)ns->href);
Daniel Veillarde6a55192002-01-14 17:11:53 +00001773 else
William M. Brack13dfa872004-09-18 04:52:08 +00001774 fprintf(output, "%s -> %s", (char *)ns->prefix,
1775 (char *)ns->href);
Daniel Veillarde6a55192002-01-14 17:11:53 +00001776 break;
1777 }
Owen Taylor3473f882001-02-23 17:55:21 +00001778 default:
1779 if (node->name != NULL)
Daniel Veillard580ced82003-03-21 21:22:48 +00001780 fprintf(output, "%s", (const char *) node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00001781 }
1782 fprintf(output, "\n");
1783}
1784
Daniel Veillard78d12092001-10-11 09:12:24 +00001785/**
1786 * xmlBoolToText:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001787 * @boolval: a bool to turn into text
Daniel Veillard78d12092001-10-11 09:12:24 +00001788 *
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001789 * Convenient way to turn bool into text
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001790 *
1791 * Returns a pointer to either "True" or "False"
1792 */
Daniel Veillard78d12092001-10-11 09:12:24 +00001793const char *
Daniel Veillardebd38c52001-11-01 08:38:12 +00001794xmlBoolToText(int boolval)
Daniel Veillard78d12092001-10-11 09:12:24 +00001795{
Daniel Veillardebd38c52001-11-01 08:38:12 +00001796 if (boolval)
Daniel Veillard78d12092001-10-11 09:12:24 +00001797 return("True");
1798 else
1799 return("False");
1800}
1801
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001802#ifdef LIBXML_XPATH_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +00001803/****************************************************************
1804 * *
Daniel Veillardf8e3db02012-09-11 13:26:36 +08001805 * The XML shell related functions *
Owen Taylor3473f882001-02-23 17:55:21 +00001806 * *
1807 ****************************************************************/
1808
Daniel Veillard78d12092001-10-11 09:12:24 +00001809
1810
Owen Taylor3473f882001-02-23 17:55:21 +00001811/*
1812 * TODO: Improvement/cleanups for the XML shell
1813 * - allow to shell out an editor on a subpart
1814 * - cleanup function registrations (with help) and calling
1815 * - provide registration routines
1816 */
1817
1818/**
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001819 * xmlShellPrintXPathError:
Daniel Veillard78d12092001-10-11 09:12:24 +00001820 * @errorType: valid xpath error id
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001821 * @arg: the argument that cause xpath to fail
Daniel Veillard78d12092001-10-11 09:12:24 +00001822 *
1823 * Print the xpath error to libxml default error channel
1824 */
1825void
1826xmlShellPrintXPathError(int errorType, const char *arg)
1827{
1828 const char *default_arg = "Result";
1829
1830 if (!arg)
1831 arg = default_arg;
1832
1833 switch (errorType) {
1834 case XPATH_UNDEFINED:
1835 xmlGenericError(xmlGenericErrorContext,
1836 "%s: no such node\n", arg);
1837 break;
1838
1839 case XPATH_BOOLEAN:
1840 xmlGenericError(xmlGenericErrorContext,
1841 "%s is a Boolean\n", arg);
1842 break;
1843 case XPATH_NUMBER:
1844 xmlGenericError(xmlGenericErrorContext,
1845 "%s is a number\n", arg);
1846 break;
1847 case XPATH_STRING:
1848 xmlGenericError(xmlGenericErrorContext,
1849 "%s is a string\n", arg);
1850 break;
1851 case XPATH_POINT:
1852 xmlGenericError(xmlGenericErrorContext,
1853 "%s is a point\n", arg);
1854 break;
1855 case XPATH_RANGE:
1856 xmlGenericError(xmlGenericErrorContext,
1857 "%s is a range\n", arg);
1858 break;
1859 case XPATH_LOCATIONSET:
1860 xmlGenericError(xmlGenericErrorContext,
1861 "%s is a range\n", arg);
1862 break;
1863 case XPATH_USERS:
1864 xmlGenericError(xmlGenericErrorContext,
1865 "%s is user-defined\n", arg);
1866 break;
1867 case XPATH_XSLT_TREE:
1868 xmlGenericError(xmlGenericErrorContext,
1869 "%s is an XSLT value tree\n", arg);
1870 break;
1871 }
Daniel Veillarda82b1822004-11-08 16:24:57 +00001872#if 0
Daniel Veillard78d12092001-10-11 09:12:24 +00001873 xmlGenericError(xmlGenericErrorContext,
1874 "Try casting the result string function (xpath builtin)\n",
1875 arg);
Daniel Veillarda82b1822004-11-08 16:24:57 +00001876#endif
Daniel Veillard78d12092001-10-11 09:12:24 +00001877}
1878
1879
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001880#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00001881/**
Daniel Veillard321be0c2002-10-08 21:26:42 +00001882 * xmlShellPrintNodeCtxt:
1883 * @ctxt : a non-null shell context
1884 * @node : a non-null node to print to the output FILE
Daniel Veillard78d12092001-10-11 09:12:24 +00001885 *
Daniel Veillard321be0c2002-10-08 21:26:42 +00001886 * Print node to the output FILE
1887 */
1888static void
1889xmlShellPrintNodeCtxt(xmlShellCtxtPtr ctxt,xmlNodePtr node)
1890{
Daniel Veillard01992e02002-10-09 10:20:30 +00001891 FILE *fp;
1892
1893 if (!node)
Daniel Veillard321be0c2002-10-08 21:26:42 +00001894 return;
Daniel Veillard01992e02002-10-09 10:20:30 +00001895 if (ctxt == NULL)
1896 fp = stdout;
1897 else
1898 fp = ctxt->output;
Daniel Veillard321be0c2002-10-08 21:26:42 +00001899
1900 if (node->type == XML_DOCUMENT_NODE)
Daniel Veillard01992e02002-10-09 10:20:30 +00001901 xmlDocDump(fp, (xmlDocPtr) node);
Daniel Veillard321be0c2002-10-08 21:26:42 +00001902 else if (node->type == XML_ATTRIBUTE_NODE)
Daniel Veillard01992e02002-10-09 10:20:30 +00001903 xmlDebugDumpAttrList(fp, (xmlAttrPtr) node, 0);
Daniel Veillard321be0c2002-10-08 21:26:42 +00001904 else
Daniel Veillard01992e02002-10-09 10:20:30 +00001905 xmlElemDump(fp, node->doc, node);
Daniel Veillard321be0c2002-10-08 21:26:42 +00001906
Daniel Veillard01992e02002-10-09 10:20:30 +00001907 fprintf(fp, "\n");
Daniel Veillard321be0c2002-10-08 21:26:42 +00001908}
1909
1910/**
1911 * xmlShellPrintNode:
1912 * @node : a non-null node to print to the output FILE
1913 *
1914 * Print node to the output FILE
Daniel Veillard78d12092001-10-11 09:12:24 +00001915 */
1916void
1917xmlShellPrintNode(xmlNodePtr node)
1918{
Daniel Veillard321be0c2002-10-08 21:26:42 +00001919 xmlShellPrintNodeCtxt(NULL, node);
Daniel Veillard78d12092001-10-11 09:12:24 +00001920}
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001921#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00001922
Daniel Veillard78d12092001-10-11 09:12:24 +00001923/**
Daniel Veillard321be0c2002-10-08 21:26:42 +00001924 * xmlShellPrintXPathResultCtxt:
1925 * @ctxt: a valid shell context
Daniel Veillard9d06d302002-01-22 18:15:52 +00001926 * @list: a valid result generated by an xpath evaluation
Daniel Veillard78d12092001-10-11 09:12:24 +00001927 *
Daniel Veillard321be0c2002-10-08 21:26:42 +00001928 * Prints result to the output FILE
Daniel Veillard78d12092001-10-11 09:12:24 +00001929 */
Daniel Veillard321be0c2002-10-08 21:26:42 +00001930static void
1931xmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt,xmlXPathObjectPtr list)
Daniel Veillard78d12092001-10-11 09:12:24 +00001932{
Daniel Veillard321be0c2002-10-08 21:26:42 +00001933 if (!ctxt)
1934 return;
Daniel Veillard78d12092001-10-11 09:12:24 +00001935
1936 if (list != NULL) {
1937 switch (list->type) {
1938 case XPATH_NODESET:{
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001939#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00001940 int indx;
1941
1942 if (list->nodesetval) {
1943 for (indx = 0; indx < list->nodesetval->nodeNr;
1944 indx++) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00001945 xmlShellPrintNodeCtxt(ctxt,
1946 list->nodesetval->nodeTab[indx]);
Daniel Veillard78d12092001-10-11 09:12:24 +00001947 }
1948 } else {
1949 xmlGenericError(xmlGenericErrorContext,
1950 "Empty node set\n");
1951 }
1952 break;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001953#else
1954 xmlGenericError(xmlGenericErrorContext,
1955 "Node set\n");
1956#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00001957 }
1958 case XPATH_BOOLEAN:
1959 xmlGenericError(xmlGenericErrorContext,
1960 "Is a Boolean:%s\n",
1961 xmlBoolToText(list->boolval));
1962 break;
1963 case XPATH_NUMBER:
1964 xmlGenericError(xmlGenericErrorContext,
1965 "Is a number:%0g\n", list->floatval);
1966 break;
1967 case XPATH_STRING:
1968 xmlGenericError(xmlGenericErrorContext,
1969 "Is a string:%s\n", list->stringval);
1970 break;
1971
1972 default:
1973 xmlShellPrintXPathError(list->type, NULL);
1974 }
1975 }
1976}
1977
1978/**
Daniel Veillard321be0c2002-10-08 21:26:42 +00001979 * xmlShellPrintXPathResult:
1980 * @list: a valid result generated by an xpath evaluation
1981 *
1982 * Prints result to the output FILE
1983 */
1984void
1985xmlShellPrintXPathResult(xmlXPathObjectPtr list)
1986{
1987 xmlShellPrintXPathResultCtxt(NULL, list);
1988}
1989
1990/**
Owen Taylor3473f882001-02-23 17:55:21 +00001991 * xmlShellList:
1992 * @ctxt: the shell context
1993 * @arg: unused
1994 * @node: a node
1995 * @node2: unused
1996 *
1997 * Implements the XML shell function "ls"
1998 * Does an Unix like listing of the given node (like a directory)
1999 *
2000 * Returns 0
2001 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002002int
Daniel Veillard321be0c2002-10-08 21:26:42 +00002003xmlShellList(xmlShellCtxtPtr ctxt,
Daniel Veillard78d12092001-10-11 09:12:24 +00002004 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2005 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2006{
Owen Taylor3473f882001-02-23 17:55:21 +00002007 xmlNodePtr cur;
Daniel Veillard321be0c2002-10-08 21:26:42 +00002008 if (!ctxt)
2009 return (0);
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002010 if (node == NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002011 fprintf(ctxt->output, "NULL\n");
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002012 return (0);
2013 }
Owen Taylor3473f882001-02-23 17:55:21 +00002014 if ((node->type == XML_DOCUMENT_NODE) ||
2015 (node->type == XML_HTML_DOCUMENT_NODE)) {
2016 cur = ((xmlDocPtr) node)->children;
Daniel Veillarde6a55192002-01-14 17:11:53 +00002017 } else if (node->type == XML_NAMESPACE_DECL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002018 xmlLsOneNode(ctxt->output, node);
Daniel Veillarde6a55192002-01-14 17:11:53 +00002019 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002020 } else if (node->children != NULL) {
2021 cur = node->children;
2022 } else {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002023 xmlLsOneNode(ctxt->output, node);
Daniel Veillard78d12092001-10-11 09:12:24 +00002024 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002025 }
2026 while (cur != NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002027 xmlLsOneNode(ctxt->output, cur);
Daniel Veillard78d12092001-10-11 09:12:24 +00002028 cur = cur->next;
Owen Taylor3473f882001-02-23 17:55:21 +00002029 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002030 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002031}
2032
2033/**
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002034 * xmlShellBase:
2035 * @ctxt: the shell context
2036 * @arg: unused
2037 * @node: a node
2038 * @node2: unused
2039 *
2040 * Implements the XML shell function "base"
2041 * dumps the current XML base of the node
2042 *
2043 * Returns 0
2044 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002045int
Daniel Veillard321be0c2002-10-08 21:26:42 +00002046xmlShellBase(xmlShellCtxtPtr ctxt,
Daniel Veillard78d12092001-10-11 09:12:24 +00002047 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2048 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2049{
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002050 xmlChar *base;
Daniel Veillard321be0c2002-10-08 21:26:42 +00002051 if (!ctxt)
2052 return 0;
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002053 if (node == NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002054 fprintf(ctxt->output, "NULL\n");
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002055 return (0);
Daniel Veillardf8e3db02012-09-11 13:26:36 +08002056 }
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002057
2058 base = xmlNodeGetBase(node->doc, node);
2059
2060 if (base == NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002061 fprintf(ctxt->output, " No base found !!!\n");
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002062 } else {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002063 fprintf(ctxt->output, "%s\n", base);
Daniel Veillard78d12092001-10-11 09:12:24 +00002064 xmlFree(base);
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002065 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002066 return (0);
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002067}
2068
Daniel Veillardb34321c2004-03-04 17:09:47 +00002069#ifdef LIBXML_TREE_ENABLED
Daniel Veillardb8c9be92001-07-09 16:01:19 +00002070/**
Daniel Veillardcfa0d812002-01-17 08:46:58 +00002071 * xmlShellSetBase:
2072 * @ctxt: the shell context
2073 * @arg: the new base
2074 * @node: a node
2075 * @node2: unused
2076 *
2077 * Implements the XML shell function "setbase"
2078 * change the current XML base of the node
2079 *
2080 * Returns 0
2081 */
2082static int
2083xmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2084 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2085 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2086{
2087 xmlNodeSetBase(node, (xmlChar*) arg);
2088 return (0);
2089}
Daniel Veillard2156d432004-03-04 15:59:36 +00002090#endif
Daniel Veillardcfa0d812002-01-17 08:46:58 +00002091
Daniel Veillardbbaa9972004-06-16 14:08:33 +00002092#ifdef LIBXML_XPATH_ENABLED
2093/**
2094 * xmlShellRegisterNamespace:
2095 * @ctxt: the shell context
2096 * @arg: a string in prefix=nsuri format
2097 * @node: unused
2098 * @node2: unused
2099 *
2100 * Implements the XML shell function "setns"
2101 * register/unregister a prefix=namespace pair
2102 * on the XPath context
2103 *
2104 * Returns 0 on success and a negative value otherwise.
2105 */
2106static int
2107xmlShellRegisterNamespace(xmlShellCtxtPtr ctxt, char *arg,
2108 xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2109{
2110 xmlChar* nsListDup;
2111 xmlChar* prefix;
2112 xmlChar* href;
2113 xmlChar* next;
2114
2115 nsListDup = xmlStrdup((xmlChar *) arg);
2116 next = nsListDup;
2117 while(next != NULL) {
2118 /* skip spaces */
2119 /*while((*next) == ' ') next++;*/
2120 if((*next) == '\0') break;
2121
2122 /* find prefix */
2123 prefix = next;
2124 next = (xmlChar*)xmlStrchr(next, '=');
2125 if(next == NULL) {
2126 fprintf(ctxt->output, "setns: prefix=[nsuri] required\n");
2127 xmlFree(nsListDup);
2128 return(-1);
2129 }
2130 *(next++) = '\0';
2131
2132 /* find href */
2133 href = next;
2134 next = (xmlChar*)xmlStrchr(next, ' ');
2135 if(next != NULL) {
2136 *(next++) = '\0';
2137 }
2138
2139 /* do register namespace */
2140 if(xmlXPathRegisterNs(ctxt->pctxt, prefix, href) != 0) {
2141 fprintf(ctxt->output,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
2142 xmlFree(nsListDup);
2143 return(-1);
2144 }
2145 }
2146
2147 xmlFree(nsListDup);
2148 return(0);
2149}
Daniel Veillard20887ee2005-07-04 09:27:40 +00002150/**
2151 * xmlShellRegisterRootNamespaces:
2152 * @ctxt: the shell context
2153 * @arg: unused
2154 * @node: the root element
2155 * @node2: unused
2156 *
2157 * Implements the XML shell function "setrootns"
2158 * which registers all namespaces declarations found on the root element.
2159 *
2160 * Returns 0 on success and a negative value otherwise.
2161 */
2162static int
2163xmlShellRegisterRootNamespaces(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
2164 xmlNodePtr root, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2165{
2166 xmlNsPtr ns;
2167
2168 if ((root == NULL) || (root->type != XML_ELEMENT_NODE) ||
2169 (root->nsDef == NULL) || (ctxt == NULL) || (ctxt->pctxt == NULL))
2170 return(-1);
2171 ns = root->nsDef;
2172 while (ns != NULL) {
2173 if (ns->prefix == NULL)
2174 xmlXPathRegisterNs(ctxt->pctxt, BAD_CAST "defaultns", ns->href);
2175 else
2176 xmlXPathRegisterNs(ctxt->pctxt, ns->prefix, ns->href);
2177 ns = ns->next;
2178 }
2179 return(0);
2180}
Daniel Veillardbbaa9972004-06-16 14:08:33 +00002181#endif
2182
Daniel Veillardcfa0d812002-01-17 08:46:58 +00002183/**
Daniel Veillard1e208222002-10-22 14:25:25 +00002184 * xmlShellGrep:
2185 * @ctxt: the shell context
2186 * @arg: the string or regular expression to find
2187 * @node: a node
2188 * @node2: unused
2189 *
2190 * Implements the XML shell function "grep"
2191 * dumps informations about the node (namespace, attributes, content).
2192 *
2193 * Returns 0
2194 */
Daniel Veillarde645e8c2002-10-22 17:35:37 +00002195static int
Daniel Veillard1e208222002-10-22 14:25:25 +00002196xmlShellGrep(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2197 char *arg, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2198{
2199 if (!ctxt)
2200 return (0);
2201 if (node == NULL)
2202 return (0);
2203 if (arg == NULL)
2204 return (0);
2205#ifdef LIBXML_REGEXP_ENABLED
2206 if ((xmlStrchr((xmlChar *) arg, '?')) ||
2207 (xmlStrchr((xmlChar *) arg, '*')) ||
2208 (xmlStrchr((xmlChar *) arg, '.')) ||
2209 (xmlStrchr((xmlChar *) arg, '['))) {
2210 }
2211#endif
2212 while (node != NULL) {
2213 if (node->type == XML_COMMENT_NODE) {
Daniel Veillarde645e8c2002-10-22 17:35:37 +00002214 if (xmlStrstr(node->content, (xmlChar *) arg)) {
Daniel Veillard1e208222002-10-22 14:25:25 +00002215
2216 fprintf(ctxt->output, "%s : ", xmlGetNodePath(node));
2217 xmlShellList(ctxt, NULL, node, NULL);
2218 }
2219 } else if (node->type == XML_TEXT_NODE) {
Daniel Veillarde645e8c2002-10-22 17:35:37 +00002220 if (xmlStrstr(node->content, (xmlChar *) arg)) {
Daniel Veillard1e208222002-10-22 14:25:25 +00002221
2222 fprintf(ctxt->output, "%s : ", xmlGetNodePath(node->parent));
Daniel Veillarde645e8c2002-10-22 17:35:37 +00002223 xmlShellList(ctxt, NULL, node->parent, NULL);
Daniel Veillard1e208222002-10-22 14:25:25 +00002224 }
2225 }
2226
2227 /*
2228 * Browse the full subtree, deep first
2229 */
2230
2231 if ((node->type == XML_DOCUMENT_NODE) ||
2232 (node->type == XML_HTML_DOCUMENT_NODE)) {
2233 node = ((xmlDocPtr) node)->children;
2234 } else if ((node->children != NULL)
2235 && (node->type != XML_ENTITY_REF_NODE)) {
2236 /* deep first */
2237 node = node->children;
2238 } else if (node->next != NULL) {
2239 /* then siblings */
2240 node = node->next;
2241 } else {
2242 /* go up to parents->next if needed */
2243 while (node != NULL) {
2244 if (node->parent != NULL) {
2245 node = node->parent;
2246 }
2247 if (node->next != NULL) {
2248 node = node->next;
2249 break;
2250 }
2251 if (node->parent == NULL) {
2252 node = NULL;
2253 break;
2254 }
2255 }
2256 }
2257 }
2258 return (0);
2259}
2260
2261/**
Owen Taylor3473f882001-02-23 17:55:21 +00002262 * xmlShellDir:
2263 * @ctxt: the shell context
2264 * @arg: unused
2265 * @node: a node
2266 * @node2: unused
2267 *
2268 * Implements the XML shell function "dir"
2269 * dumps informations about the node (namespace, attributes, content).
2270 *
2271 * Returns 0
2272 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002273int
2274xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2275 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2276 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2277{
Daniel Veillard321be0c2002-10-08 21:26:42 +00002278 if (!ctxt)
2279 return (0);
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002280 if (node == NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002281 fprintf(ctxt->output, "NULL\n");
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002282 return (0);
Daniel Veillardf8e3db02012-09-11 13:26:36 +08002283 }
Owen Taylor3473f882001-02-23 17:55:21 +00002284 if ((node->type == XML_DOCUMENT_NODE) ||
2285 (node->type == XML_HTML_DOCUMENT_NODE)) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002286 xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node);
Owen Taylor3473f882001-02-23 17:55:21 +00002287 } else if (node->type == XML_ATTRIBUTE_NODE) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002288 xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0);
Owen Taylor3473f882001-02-23 17:55:21 +00002289 } else {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002290 xmlDebugDumpOneNode(ctxt->output, node, 0);
Owen Taylor3473f882001-02-23 17:55:21 +00002291 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002292 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002293}
2294
Daniel Veillard29b17482004-08-16 00:39:03 +00002295/**
2296 * xmlShellSetContent:
2297 * @ctxt: the shell context
2298 * @value: the content as a string
2299 * @node: a node
2300 * @node2: unused
2301 *
2302 * Implements the XML shell function "dir"
2303 * dumps informations about the node (namespace, attributes, content).
2304 *
2305 * Returns 0
2306 */
2307static int
2308xmlShellSetContent(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2309 char *value, xmlNodePtr node,
2310 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2311{
2312 xmlNodePtr results;
2313 xmlParserErrors ret;
2314
2315 if (!ctxt)
2316 return (0);
2317 if (node == NULL) {
2318 fprintf(ctxt->output, "NULL\n");
2319 return (0);
2320 }
2321 if (value == NULL) {
2322 fprintf(ctxt->output, "NULL\n");
2323 return (0);
2324 }
2325
2326 ret = xmlParseInNodeContext(node, value, strlen(value), 0, &results);
2327 if (ret == XML_ERR_OK) {
2328 if (node->children != NULL) {
2329 xmlFreeNodeList(node->children);
2330 node->children = NULL;
2331 node->last = NULL;
2332 }
2333 xmlAddChildList(node, results);
2334 } else {
2335 fprintf(ctxt->output, "failed to parse content\n");
2336 }
2337 return (0);
2338}
2339
Daniel Veillard522bc602004-02-21 11:53:09 +00002340#ifdef LIBXML_SCHEMAS_ENABLED
2341/**
2342 * xmlShellRNGValidate:
2343 * @ctxt: the shell context
2344 * @schemas: the path to the Relax-NG schemas
2345 * @node: a node
2346 * @node2: unused
2347 *
2348 * Implements the XML shell function "relaxng"
2349 * validating the instance against a Relax-NG schemas
2350 *
2351 * Returns 0
2352 */
2353static int
2354xmlShellRNGValidate(xmlShellCtxtPtr sctxt, char *schemas,
2355 xmlNodePtr node ATTRIBUTE_UNUSED,
2356 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2357{
2358 xmlRelaxNGPtr relaxngschemas;
2359 xmlRelaxNGParserCtxtPtr ctxt;
2360 xmlRelaxNGValidCtxtPtr vctxt;
2361 int ret;
2362
2363 ctxt = xmlRelaxNGNewParserCtxt(schemas);
2364 xmlRelaxNGSetParserErrors(ctxt,
2365 (xmlRelaxNGValidityErrorFunc) fprintf,
2366 (xmlRelaxNGValidityWarningFunc) fprintf,
2367 stderr);
2368 relaxngschemas = xmlRelaxNGParse(ctxt);
2369 xmlRelaxNGFreeParserCtxt(ctxt);
2370 if (relaxngschemas == NULL) {
2371 xmlGenericError(xmlGenericErrorContext,
2372 "Relax-NG schema %s failed to compile\n", schemas);
2373 return(-1);
2374 }
2375 vctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
2376 xmlRelaxNGSetValidErrors(vctxt,
2377 (xmlRelaxNGValidityErrorFunc) fprintf,
2378 (xmlRelaxNGValidityWarningFunc) fprintf,
2379 stderr);
2380 ret = xmlRelaxNGValidateDoc(vctxt, sctxt->doc);
2381 if (ret == 0) {
2382 fprintf(stderr, "%s validates\n", sctxt->filename);
2383 } else if (ret > 0) {
2384 fprintf(stderr, "%s fails to validate\n", sctxt->filename);
2385 } else {
2386 fprintf(stderr, "%s validation generated an internal error\n",
2387 sctxt->filename);
2388 }
2389 xmlRelaxNGFreeValidCtxt(vctxt);
2390 if (relaxngschemas != NULL)
2391 xmlRelaxNGFree(relaxngschemas);
2392 return(0);
2393}
2394#endif
2395
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002396#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +00002397/**
2398 * xmlShellCat:
2399 * @ctxt: the shell context
2400 * @arg: unused
2401 * @node: a node
2402 * @node2: unused
2403 *
2404 * Implements the XML shell function "cat"
2405 * dumps the serialization node content (XML or HTML).
2406 *
2407 * Returns 0
2408 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002409int
2410xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
2411 xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2412{
Daniel Veillard321be0c2002-10-08 21:26:42 +00002413 if (!ctxt)
2414 return (0);
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002415 if (node == NULL) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002416 fprintf(ctxt->output, "NULL\n");
Daniel Veillard5e926fa2002-01-22 21:44:25 +00002417 return (0);
Daniel Veillardf8e3db02012-09-11 13:26:36 +08002418 }
Owen Taylor3473f882001-02-23 17:55:21 +00002419 if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) {
2420#ifdef LIBXML_HTML_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002421 if (node->type == XML_HTML_DOCUMENT_NODE)
Daniel Veillard321be0c2002-10-08 21:26:42 +00002422 htmlDocDump(ctxt->output, (htmlDocPtr) node);
Daniel Veillard78d12092001-10-11 09:12:24 +00002423 else
Daniel Veillard321be0c2002-10-08 21:26:42 +00002424 htmlNodeDumpFile(ctxt->output, ctxt->doc, node);
Owen Taylor3473f882001-02-23 17:55:21 +00002425#else
Daniel Veillard78d12092001-10-11 09:12:24 +00002426 if (node->type == XML_DOCUMENT_NODE)
Daniel Veillard321be0c2002-10-08 21:26:42 +00002427 xmlDocDump(ctxt->output, (xmlDocPtr) node);
Daniel Veillard78d12092001-10-11 09:12:24 +00002428 else
Daniel Veillard321be0c2002-10-08 21:26:42 +00002429 xmlElemDump(ctxt->output, ctxt->doc, node);
Owen Taylor3473f882001-02-23 17:55:21 +00002430#endif /* LIBXML_HTML_ENABLED */
2431 } else {
Daniel Veillard78d12092001-10-11 09:12:24 +00002432 if (node->type == XML_DOCUMENT_NODE)
Daniel Veillard321be0c2002-10-08 21:26:42 +00002433 xmlDocDump(ctxt->output, (xmlDocPtr) node);
Daniel Veillard78d12092001-10-11 09:12:24 +00002434 else
Daniel Veillard321be0c2002-10-08 21:26:42 +00002435 xmlElemDump(ctxt->output, ctxt->doc, node);
Owen Taylor3473f882001-02-23 17:55:21 +00002436 }
Daniel Veillard321be0c2002-10-08 21:26:42 +00002437 fprintf(ctxt->output, "\n");
Daniel Veillard78d12092001-10-11 09:12:24 +00002438 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002439}
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002440#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00002441
2442/**
2443 * xmlShellLoad:
2444 * @ctxt: the shell context
2445 * @filename: the file name
2446 * @node: unused
2447 * @node2: unused
2448 *
2449 * Implements the XML shell function "load"
2450 * loads a new document specified by the filename
2451 *
2452 * Returns 0 or -1 if loading failed
2453 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002454int
2455xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename,
2456 xmlNodePtr node ATTRIBUTE_UNUSED,
2457 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2458{
Owen Taylor3473f882001-02-23 17:55:21 +00002459 xmlDocPtr doc;
2460 int html = 0;
2461
Daniel Veillarda82b1822004-11-08 16:24:57 +00002462 if ((ctxt == NULL) || (filename == NULL)) return(-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002463 if (ctxt->doc != NULL)
Daniel Veillard78d12092001-10-11 09:12:24 +00002464 html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE);
Owen Taylor3473f882001-02-23 17:55:21 +00002465
2466 if (html) {
2467#ifdef LIBXML_HTML_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002468 doc = htmlParseFile(filename, NULL);
2469#else
Daniel Veillard321be0c2002-10-08 21:26:42 +00002470 fprintf(ctxt->output, "HTML support not compiled in\n");
Daniel Veillard78d12092001-10-11 09:12:24 +00002471 doc = NULL;
Owen Taylor3473f882001-02-23 17:55:21 +00002472#endif /* LIBXML_HTML_ENABLED */
2473 } else {
Daniel Veillardebe25d42004-03-25 09:35:49 +00002474 doc = xmlReadFile(filename,NULL,0);
Owen Taylor3473f882001-02-23 17:55:21 +00002475 }
2476 if (doc != NULL) {
2477 if (ctxt->loaded == 1) {
Daniel Veillard78d12092001-10-11 09:12:24 +00002478 xmlFreeDoc(ctxt->doc);
2479 }
2480 ctxt->loaded = 1;
Owen Taylor3473f882001-02-23 17:55:21 +00002481#ifdef LIBXML_XPATH_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002482 xmlXPathFreeContext(ctxt->pctxt);
Owen Taylor3473f882001-02-23 17:55:21 +00002483#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00002484 xmlFree(ctxt->filename);
2485 ctxt->doc = doc;
2486 ctxt->node = (xmlNodePtr) doc;
Owen Taylor3473f882001-02-23 17:55:21 +00002487#ifdef LIBXML_XPATH_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002488 ctxt->pctxt = xmlXPathNewContext(doc);
Owen Taylor3473f882001-02-23 17:55:21 +00002489#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard85095e22003-04-23 13:56:44 +00002490 ctxt->filename = (char *) xmlCanonicPath((xmlChar *) filename);
Owen Taylor3473f882001-02-23 17:55:21 +00002491 } else
Daniel Veillard78d12092001-10-11 09:12:24 +00002492 return (-1);
2493 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002494}
2495
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002496#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +00002497/**
2498 * xmlShellWrite:
2499 * @ctxt: the shell context
2500 * @filename: the file name
2501 * @node: a node in the tree
2502 * @node2: unused
2503 *
2504 * Implements the XML shell function "write"
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002505 * Write the current node to the filename, it saves the serialization
Owen Taylor3473f882001-02-23 17:55:21 +00002506 * of the subtree under the @node specified
2507 *
2508 * Returns 0 or -1 in case of error
2509 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002510int
Owen Taylor3473f882001-02-23 17:55:21 +00002511xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,
Daniel Veillard78d12092001-10-11 09:12:24 +00002512 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2513{
Owen Taylor3473f882001-02-23 17:55:21 +00002514 if (node == NULL)
Daniel Veillard78d12092001-10-11 09:12:24 +00002515 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002516 if ((filename == NULL) || (filename[0] == 0)) {
Daniel Veillard78d12092001-10-11 09:12:24 +00002517 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002518 }
2519#ifdef W_OK
2520 if (access((char *) filename, W_OK)) {
2521 xmlGenericError(xmlGenericErrorContext,
Daniel Veillard78d12092001-10-11 09:12:24 +00002522 "Cannot write to %s\n", filename);
2523 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002524 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002525#endif
2526 switch (node->type) {
Owen Taylor3473f882001-02-23 17:55:21 +00002527 case XML_DOCUMENT_NODE:
Daniel Veillard78d12092001-10-11 09:12:24 +00002528 if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {
2529 xmlGenericError(xmlGenericErrorContext,
2530 "Failed to write to %s\n", filename);
2531 return (-1);
2532 }
2533 break;
Owen Taylor3473f882001-02-23 17:55:21 +00002534 case XML_HTML_DOCUMENT_NODE:
2535#ifdef LIBXML_HTML_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002536 if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {
2537 xmlGenericError(xmlGenericErrorContext,
2538 "Failed to write to %s\n", filename);
2539 return (-1);
2540 }
Owen Taylor3473f882001-02-23 17:55:21 +00002541#else
Daniel Veillard78d12092001-10-11 09:12:24 +00002542 if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {
2543 xmlGenericError(xmlGenericErrorContext,
2544 "Failed to write to %s\n", filename);
2545 return (-1);
2546 }
Owen Taylor3473f882001-02-23 17:55:21 +00002547#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00002548 break;
2549 default:{
2550 FILE *f;
Owen Taylor3473f882001-02-23 17:55:21 +00002551
Daniel Veillard78d12092001-10-11 09:12:24 +00002552 f = fopen((char *) filename, "w");
2553 if (f == NULL) {
2554 xmlGenericError(xmlGenericErrorContext,
2555 "Failed to write to %s\n", filename);
2556 return (-1);
2557 }
2558 xmlElemDump(f, ctxt->doc, node);
2559 fclose(f);
2560 }
Owen Taylor3473f882001-02-23 17:55:21 +00002561 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002562 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002563}
2564
2565/**
2566 * xmlShellSave:
2567 * @ctxt: the shell context
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002568 * @filename: the file name (optional)
Owen Taylor3473f882001-02-23 17:55:21 +00002569 * @node: unused
2570 * @node2: unused
2571 *
2572 * Implements the XML shell function "save"
2573 * Write the current document to the filename, or it's original name
2574 *
2575 * Returns 0 or -1 in case of error
2576 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002577int
2578xmlShellSave(xmlShellCtxtPtr ctxt, char *filename,
2579 xmlNodePtr node ATTRIBUTE_UNUSED,
2580 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2581{
Daniel Veillarda82b1822004-11-08 16:24:57 +00002582 if ((ctxt == NULL) || (ctxt->doc == NULL))
Daniel Veillard78d12092001-10-11 09:12:24 +00002583 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002584 if ((filename == NULL) || (filename[0] == 0))
2585 filename = ctxt->filename;
Daniel Veillarda82b1822004-11-08 16:24:57 +00002586 if (filename == NULL)
2587 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002588#ifdef W_OK
2589 if (access((char *) filename, W_OK)) {
2590 xmlGenericError(xmlGenericErrorContext,
Daniel Veillard78d12092001-10-11 09:12:24 +00002591 "Cannot save to %s\n", filename);
2592 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002593 }
2594#endif
Daniel Veillard78d12092001-10-11 09:12:24 +00002595 switch (ctxt->doc->type) {
Owen Taylor3473f882001-02-23 17:55:21 +00002596 case XML_DOCUMENT_NODE:
Daniel Veillard78d12092001-10-11 09:12:24 +00002597 if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
2598 xmlGenericError(xmlGenericErrorContext,
2599 "Failed to save to %s\n", filename);
2600 }
2601 break;
Owen Taylor3473f882001-02-23 17:55:21 +00002602 case XML_HTML_DOCUMENT_NODE:
2603#ifdef LIBXML_HTML_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002604 if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {
2605 xmlGenericError(xmlGenericErrorContext,
2606 "Failed to save to %s\n", filename);
2607 }
Owen Taylor3473f882001-02-23 17:55:21 +00002608#else
Daniel Veillard78d12092001-10-11 09:12:24 +00002609 if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
2610 xmlGenericError(xmlGenericErrorContext,
2611 "Failed to save to %s\n", filename);
2612 }
Owen Taylor3473f882001-02-23 17:55:21 +00002613#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00002614 break;
2615 default:
2616 xmlGenericError(xmlGenericErrorContext,
2617 "To save to subparts of a document use the 'write' command\n");
2618 return (-1);
2619
Owen Taylor3473f882001-02-23 17:55:21 +00002620 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002621 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002622}
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002623#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00002624
Daniel Veillardf54cd532004-02-25 11:52:31 +00002625#ifdef LIBXML_VALID_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +00002626/**
2627 * xmlShellValidate:
2628 * @ctxt: the shell context
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002629 * @dtd: the DTD URI (optional)
Owen Taylor3473f882001-02-23 17:55:21 +00002630 * @node: unused
2631 * @node2: unused
2632 *
2633 * Implements the XML shell function "validate"
2634 * Validate the document, if a DTD path is provided, then the validation
2635 * is done against the given DTD.
2636 *
2637 * Returns 0 or -1 in case of error
2638 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002639int
2640xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd,
2641 xmlNodePtr node ATTRIBUTE_UNUSED,
2642 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2643{
Owen Taylor3473f882001-02-23 17:55:21 +00002644 xmlValidCtxt vctxt;
2645 int res = -1;
2646
Daniel Veillarda82b1822004-11-08 16:24:57 +00002647 if ((ctxt == NULL) || (ctxt->doc == NULL)) return(-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002648 vctxt.userData = stderr;
2649 vctxt.error = (xmlValidityErrorFunc) fprintf;
2650 vctxt.warning = (xmlValidityWarningFunc) fprintf;
2651
2652 if ((dtd == NULL) || (dtd[0] == 0)) {
2653 res = xmlValidateDocument(&vctxt, ctxt->doc);
2654 } else {
2655 xmlDtdPtr subset;
2656
Daniel Veillard78d12092001-10-11 09:12:24 +00002657 subset = xmlParseDTD(NULL, (xmlChar *) dtd);
2658 if (subset != NULL) {
Owen Taylor3473f882001-02-23 17:55:21 +00002659 res = xmlValidateDtd(&vctxt, ctxt->doc, subset);
2660
Daniel Veillard78d12092001-10-11 09:12:24 +00002661 xmlFreeDtd(subset);
2662 }
Owen Taylor3473f882001-02-23 17:55:21 +00002663 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002664 return (res);
Owen Taylor3473f882001-02-23 17:55:21 +00002665}
Daniel Veillardf54cd532004-02-25 11:52:31 +00002666#endif /* LIBXML_VALID_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00002667
2668/**
2669 * xmlShellDu:
2670 * @ctxt: the shell context
2671 * @arg: unused
2672 * @tree: a node defining a subtree
2673 * @node2: unused
2674 *
2675 * Implements the XML shell function "du"
2676 * show the structure of the subtree under node @tree
2677 * If @tree is null, the command works on the current node.
2678 *
2679 * Returns 0 or -1 in case of error
2680 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002681int
Daniel Veillard321be0c2002-10-08 21:26:42 +00002682xmlShellDu(xmlShellCtxtPtr ctxt,
Daniel Veillard78d12092001-10-11 09:12:24 +00002683 char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree,
2684 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2685{
Owen Taylor3473f882001-02-23 17:55:21 +00002686 xmlNodePtr node;
Daniel Veillard78d12092001-10-11 09:12:24 +00002687 int indent = 0, i;
Owen Taylor3473f882001-02-23 17:55:21 +00002688
Daniel Veillard321be0c2002-10-08 21:26:42 +00002689 if (!ctxt)
2690 return (-1);
2691
Daniel Veillard78d12092001-10-11 09:12:24 +00002692 if (tree == NULL)
2693 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002694 node = tree;
2695 while (node != NULL) {
2696 if ((node->type == XML_DOCUMENT_NODE) ||
2697 (node->type == XML_HTML_DOCUMENT_NODE)) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002698 fprintf(ctxt->output, "/\n");
Daniel Veillard78d12092001-10-11 09:12:24 +00002699 } else if (node->type == XML_ELEMENT_NODE) {
2700 for (i = 0; i < indent; i++)
Daniel Veillard321be0c2002-10-08 21:26:42 +00002701 fprintf(ctxt->output, " ");
Ryan40db1ee2012-05-07 17:04:04 +08002702 if ((node->ns) && (node->ns->prefix))
2703 fprintf(ctxt->output, "%s:", node->ns->prefix);
Daniel Veillard321be0c2002-10-08 21:26:42 +00002704 fprintf(ctxt->output, "%s\n", node->name);
Daniel Veillard78d12092001-10-11 09:12:24 +00002705 } else {
2706 }
Owen Taylor3473f882001-02-23 17:55:21 +00002707
Daniel Veillard78d12092001-10-11 09:12:24 +00002708 /*
2709 * Browse the full subtree, deep first
2710 */
Owen Taylor3473f882001-02-23 17:55:21 +00002711
2712 if ((node->type == XML_DOCUMENT_NODE) ||
2713 (node->type == XML_HTML_DOCUMENT_NODE)) {
Daniel Veillard78d12092001-10-11 09:12:24 +00002714 node = ((xmlDocPtr) node)->children;
2715 } else if ((node->children != NULL)
2716 && (node->type != XML_ENTITY_REF_NODE)) {
2717 /* deep first */
2718 node = node->children;
2719 indent++;
2720 } else if ((node != tree) && (node->next != NULL)) {
2721 /* then siblings */
2722 node = node->next;
2723 } else if (node != tree) {
2724 /* go up to parents->next if needed */
2725 while (node != tree) {
2726 if (node->parent != NULL) {
2727 node = node->parent;
2728 indent--;
2729 }
2730 if ((node != tree) && (node->next != NULL)) {
2731 node = node->next;
2732 break;
2733 }
2734 if (node->parent == NULL) {
2735 node = NULL;
2736 break;
2737 }
2738 if (node == tree) {
2739 node = NULL;
2740 break;
2741 }
2742 }
2743 /* exit condition */
2744 if (node == tree)
2745 node = NULL;
2746 } else
2747 node = NULL;
Owen Taylor3473f882001-02-23 17:55:21 +00002748 }
Daniel Veillard78d12092001-10-11 09:12:24 +00002749 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002750}
2751
2752/**
2753 * xmlShellPwd:
2754 * @ctxt: the shell context
2755 * @buffer: the output buffer
Daniel Veillardf8e3db02012-09-11 13:26:36 +08002756 * @node: a node
Owen Taylor3473f882001-02-23 17:55:21 +00002757 * @node2: unused
2758 *
2759 * Implements the XML shell function "pwd"
2760 * Show the full path from the root to the node, if needed building
2761 * thumblers when similar elements exists at a given ancestor level.
2762 * The output is compatible with XPath commands.
2763 *
2764 * Returns 0 or -1 in case of error
2765 */
Daniel Veillard78d12092001-10-11 09:12:24 +00002766int
2767xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
2768 xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2769{
Daniel Veillardc6e013a2001-11-10 10:08:57 +00002770 xmlChar *path;
Owen Taylor3473f882001-02-23 17:55:21 +00002771
Daniel Veillarda82b1822004-11-08 16:24:57 +00002772 if ((node == NULL) || (buffer == NULL))
Daniel Veillard78d12092001-10-11 09:12:24 +00002773 return (-1);
Owen Taylor3473f882001-02-23 17:55:21 +00002774
Daniel Veillardc6e013a2001-11-10 10:08:57 +00002775 path = xmlGetNodePath(node);
2776 if (path == NULL)
2777 return (-1);
2778
2779 /*
2780 * This test prevents buffer overflow, because this routine
2781 * is only called by xmlShell, in which the second argument is
2782 * 500 chars long.
2783 * It is a dirty hack before a cleaner solution is found.
2784 * Documentation should mention that the second argument must
2785 * be at least 500 chars long, and could be stripped if too long.
2786 */
2787 snprintf(buffer, 499, "%s", path);
2788 buffer[499] = '0';
2789 xmlFree(path);
2790
Daniel Veillard78d12092001-10-11 09:12:24 +00002791 return (0);
Owen Taylor3473f882001-02-23 17:55:21 +00002792}
2793
2794/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00002795 * xmlShell:
Owen Taylor3473f882001-02-23 17:55:21 +00002796 * @doc: the initial document
2797 * @filename: the output buffer
2798 * @input: the line reading function
Daniel Veillard321be0c2002-10-08 21:26:42 +00002799 * @output: the output FILE*, defaults to stdout if NULL
Owen Taylor3473f882001-02-23 17:55:21 +00002800 *
Daniel Veillardf8e3db02012-09-11 13:26:36 +08002801 * Implements the XML shell
Owen Taylor3473f882001-02-23 17:55:21 +00002802 * This allow to load, validate, view, modify and save a document
2803 * using a environment similar to a UNIX commandline.
2804 */
2805void
2806xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
Daniel Veillard78d12092001-10-11 09:12:24 +00002807 FILE * output)
2808{
Owen Taylor3473f882001-02-23 17:55:21 +00002809 char prompt[500] = "/ > ";
2810 char *cmdline = NULL, *cur;
Owen Taylor3473f882001-02-23 17:55:21 +00002811 char command[100];
2812 char arg[400];
2813 int i;
2814 xmlShellCtxtPtr ctxt;
2815 xmlXPathObjectPtr list;
2816
2817 if (doc == NULL)
2818 return;
2819 if (filename == NULL)
2820 return;
2821 if (input == NULL)
2822 return;
2823 if (output == NULL)
Daniel Veillard321be0c2002-10-08 21:26:42 +00002824 output = stdout;
Owen Taylor3473f882001-02-23 17:55:21 +00002825 ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt));
Daniel Veillard78d12092001-10-11 09:12:24 +00002826 if (ctxt == NULL)
Owen Taylor3473f882001-02-23 17:55:21 +00002827 return;
2828 ctxt->loaded = 0;
2829 ctxt->doc = doc;
2830 ctxt->input = input;
2831 ctxt->output = output;
2832 ctxt->filename = (char *) xmlStrdup((xmlChar *) filename);
Daniel Veillard78d12092001-10-11 09:12:24 +00002833 ctxt->node = (xmlNodePtr) ctxt->doc;
Owen Taylor3473f882001-02-23 17:55:21 +00002834
2835#ifdef LIBXML_XPATH_ENABLED
2836 ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
2837 if (ctxt->pctxt == NULL) {
Daniel Veillard78d12092001-10-11 09:12:24 +00002838 xmlFree(ctxt);
2839 return;
Owen Taylor3473f882001-02-23 17:55:21 +00002840 }
2841#endif /* LIBXML_XPATH_ENABLED */
2842 while (1) {
2843 if (ctxt->node == (xmlNodePtr) ctxt->doc)
Aleksey Sanin49cc9752002-06-14 17:07:10 +00002844 snprintf(prompt, sizeof(prompt), "%s > ", "/");
Ryan40db1ee2012-05-07 17:04:04 +08002845 else if ((ctxt->node != NULL) && (ctxt->node->name) &&
2846 (ctxt->node->ns) && (ctxt->node->ns->prefix))
2847 snprintf(prompt, sizeof(prompt), "%s:%s > ",
2848 (ctxt->node->ns->prefix), ctxt->node->name);
Daniel Veillard7a985a12003-07-06 17:57:42 +00002849 else if ((ctxt->node != NULL) && (ctxt->node->name))
Daniel Veillard78d12092001-10-11 09:12:24 +00002850 snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
Owen Taylor3473f882001-02-23 17:55:21 +00002851 else
Aleksey Sanin49cc9752002-06-14 17:07:10 +00002852 snprintf(prompt, sizeof(prompt), "? > ");
Owen Taylor3473f882001-02-23 17:55:21 +00002853 prompt[sizeof(prompt) - 1] = 0;
2854
Daniel Veillard78d12092001-10-11 09:12:24 +00002855 /*
2856 * Get a new command line
2857 */
Owen Taylor3473f882001-02-23 17:55:21 +00002858 cmdline = ctxt->input(prompt);
Daniel Veillard78d12092001-10-11 09:12:24 +00002859 if (cmdline == NULL)
2860 break;
Owen Taylor3473f882001-02-23 17:55:21 +00002861
Daniel Veillard78d12092001-10-11 09:12:24 +00002862 /*
2863 * Parse the command itself
2864 */
2865 cur = cmdline;
Daniel Veillard78d12092001-10-11 09:12:24 +00002866 while ((*cur == ' ') || (*cur == '\t'))
2867 cur++;
2868 i = 0;
2869 while ((*cur != ' ') && (*cur != '\t') &&
2870 (*cur != '\n') && (*cur != '\r')) {
2871 if (*cur == 0)
2872 break;
2873 command[i++] = *cur++;
2874 }
2875 command[i] = 0;
2876 if (i == 0)
2877 continue;
Owen Taylor3473f882001-02-23 17:55:21 +00002878
Daniel Veillard78d12092001-10-11 09:12:24 +00002879 /*
2880 * Parse the argument
2881 */
2882 while ((*cur == ' ') || (*cur == '\t'))
2883 cur++;
2884 i = 0;
2885 while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
2886 if (*cur == 0)
2887 break;
2888 arg[i++] = *cur++;
2889 }
2890 arg[i] = 0;
Owen Taylor3473f882001-02-23 17:55:21 +00002891
Daniel Veillard78d12092001-10-11 09:12:24 +00002892 /*
2893 * start interpreting the command
2894 */
Owen Taylor3473f882001-02-23 17:55:21 +00002895 if (!strcmp(command, "exit"))
Daniel Veillard78d12092001-10-11 09:12:24 +00002896 break;
Owen Taylor3473f882001-02-23 17:55:21 +00002897 if (!strcmp(command, "quit"))
Daniel Veillard78d12092001-10-11 09:12:24 +00002898 break;
Owen Taylor3473f882001-02-23 17:55:21 +00002899 if (!strcmp(command, "bye"))
Daniel Veillard78d12092001-10-11 09:12:24 +00002900 break;
Daniel Veillard5004f422001-11-08 13:53:05 +00002901 if (!strcmp(command, "help")) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002902 fprintf(ctxt->output, "\tbase display XML base of the node\n");
2903 fprintf(ctxt->output, "\tsetbase URI change the XML base of the node\n");
2904 fprintf(ctxt->output, "\tbye leave shell\n");
2905 fprintf(ctxt->output, "\tcat [node] display node or current node\n");
2906 fprintf(ctxt->output, "\tcd [path] change directory to path or to root\n");
2907 fprintf(ctxt->output, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n");
2908 fprintf(ctxt->output, "\tdu [path] show the structure of the subtree under path or the current node\n");
2909 fprintf(ctxt->output, "\texit leave shell\n");
2910 fprintf(ctxt->output, "\thelp display this help\n");
2911 fprintf(ctxt->output, "\tfree display memory usage\n");
2912 fprintf(ctxt->output, "\tload [name] load a new document with name\n");
2913 fprintf(ctxt->output, "\tls [path] list contents of path or the current directory\n");
Daniel Veillardc14c3892004-08-16 12:34:50 +00002914 fprintf(ctxt->output, "\tset xml_fragment replace the current node content with the fragment parsed in context\n");
Daniel Veillard2070c482002-01-22 22:12:19 +00002915#ifdef LIBXML_XPATH_ENABLED
Daniel Veillard321be0c2002-10-08 21:26:42 +00002916 fprintf(ctxt->output, "\txpath expr evaluate the XPath expression in that context and print the result\n");
Daniel Veillardbbaa9972004-06-16 14:08:33 +00002917 fprintf(ctxt->output, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n");
2918 fprintf(ctxt->output, "\t format for nsreg is: prefix=[nsuri] (i.e. prefix= unsets a prefix)\n");
Daniel Veillard20887ee2005-07-04 09:27:40 +00002919 fprintf(ctxt->output, "\tsetrootns register all namespace found on the root element\n");
2920 fprintf(ctxt->output, "\t the default namespace if any uses 'defaultns' prefix\n");
Daniel Veillard2070c482002-01-22 22:12:19 +00002921#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard321be0c2002-10-08 21:26:42 +00002922 fprintf(ctxt->output, "\tpwd display current working directory\n");
Ryan0cd29a32012-05-07 19:53:19 +08002923 fprintf(ctxt->output, "\twhereis display absolute path of [path] or current working directory\n");
Daniel Veillard321be0c2002-10-08 21:26:42 +00002924 fprintf(ctxt->output, "\tquit leave shell\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002925#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard321be0c2002-10-08 21:26:42 +00002926 fprintf(ctxt->output, "\tsave [name] save this document to name or the original name\n");
Daniel Veillard321be0c2002-10-08 21:26:42 +00002927 fprintf(ctxt->output, "\twrite [name] write the current node to the filename\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002928#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardf54cd532004-02-25 11:52:31 +00002929#ifdef LIBXML_VALID_ENABLED
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002930 fprintf(ctxt->output, "\tvalidate check the document for errors\n");
Daniel Veillardf54cd532004-02-25 11:52:31 +00002931#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard522bc602004-02-21 11:53:09 +00002932#ifdef LIBXML_SCHEMAS_ENABLED
2933 fprintf(ctxt->output, "\trelaxng rng validate the document agaisnt the Relax-NG schemas\n");
2934#endif
Daniel Veillard1e208222002-10-22 14:25:25 +00002935 fprintf(ctxt->output, "\tgrep string search for a string in the subtree\n");
Daniel Veillardf54cd532004-02-25 11:52:31 +00002936#ifdef LIBXML_VALID_ENABLED
Daniel Veillard5004f422001-11-08 13:53:05 +00002937 } else if (!strcmp(command, "validate")) {
Daniel Veillard78d12092001-10-11 09:12:24 +00002938 xmlShellValidate(ctxt, arg, NULL, NULL);
Daniel Veillardf54cd532004-02-25 11:52:31 +00002939#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00002940 } else if (!strcmp(command, "load")) {
2941 xmlShellLoad(ctxt, arg, NULL, NULL);
Daniel Veillard522bc602004-02-21 11:53:09 +00002942#ifdef LIBXML_SCHEMAS_ENABLED
2943 } else if (!strcmp(command, "relaxng")) {
2944 xmlShellRNGValidate(ctxt, arg, NULL, NULL);
2945#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002946#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00002947 } else if (!strcmp(command, "save")) {
2948 xmlShellSave(ctxt, arg, NULL, NULL);
2949 } else if (!strcmp(command, "write")) {
Daniel Veillarda82b1822004-11-08 16:24:57 +00002950 if ((arg == NULL) || (arg[0] == 0))
2951 xmlGenericError(xmlGenericErrorContext,
2952 "Write command requires a filename argument\n");
2953 else
Gwenn Kahzce5f9a72010-11-04 10:48:25 +01002954 xmlShellWrite(ctxt, arg, ctxt->node, NULL);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002955#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard1e208222002-10-22 14:25:25 +00002956 } else if (!strcmp(command, "grep")) {
2957 xmlShellGrep(ctxt, arg, ctxt->node, NULL);
Daniel Veillard78d12092001-10-11 09:12:24 +00002958 } else if (!strcmp(command, "free")) {
2959 if (arg[0] == 0) {
Daniel Veillard321be0c2002-10-08 21:26:42 +00002960 xmlMemShow(ctxt->output, 0);
Daniel Veillard78d12092001-10-11 09:12:24 +00002961 } else {
2962 int len = 0;
Owen Taylor3473f882001-02-23 17:55:21 +00002963
Daniel Veillard78d12092001-10-11 09:12:24 +00002964 sscanf(arg, "%d", &len);
Daniel Veillard321be0c2002-10-08 21:26:42 +00002965 xmlMemShow(ctxt->output, len);
Daniel Veillard78d12092001-10-11 09:12:24 +00002966 }
2967 } else if (!strcmp(command, "pwd")) {
2968 char dir[500];
Owen Taylor3473f882001-02-23 17:55:21 +00002969
Daniel Veillard78d12092001-10-11 09:12:24 +00002970 if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
Daniel Veillard321be0c2002-10-08 21:26:42 +00002971 fprintf(ctxt->output, "%s\n", dir);
Daniel Veillard78d12092001-10-11 09:12:24 +00002972 } else if (!strcmp(command, "du")) {
Ryan40db1ee2012-05-07 17:04:04 +08002973 if (arg[0] == 0) {
2974 xmlShellDu(ctxt, NULL, ctxt->node, NULL);
2975 } else {
2976 ctxt->pctxt->node = ctxt->node;
2977#ifdef LIBXML_XPATH_ENABLED
2978 ctxt->pctxt->node = ctxt->node;
2979 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
2980#else
2981 list = NULL;
2982#endif /* LIBXML_XPATH_ENABLED */
2983 if (list != NULL) {
2984 switch (list->type) {
2985 case XPATH_UNDEFINED:
2986 xmlGenericError(xmlGenericErrorContext,
2987 "%s: no such node\n", arg);
2988 break;
2989 case XPATH_NODESET:{
2990 int indx;
2991
2992 if (list->nodesetval == NULL)
2993 break;
2994
2995 for (indx = 0;
2996 indx < list->nodesetval->nodeNr;
2997 indx++)
2998 xmlShellDu(ctxt, NULL,
2999 list->nodesetval->
3000 nodeTab[indx], NULL);
3001 break;
3002 }
3003 case XPATH_BOOLEAN:
3004 xmlGenericError(xmlGenericErrorContext,
3005 "%s is a Boolean\n", arg);
3006 break;
3007 case XPATH_NUMBER:
3008 xmlGenericError(xmlGenericErrorContext,
3009 "%s is a number\n", arg);
3010 break;
3011 case XPATH_STRING:
3012 xmlGenericError(xmlGenericErrorContext,
3013 "%s is a string\n", arg);
3014 break;
3015 case XPATH_POINT:
3016 xmlGenericError(xmlGenericErrorContext,
3017 "%s is a point\n", arg);
3018 break;
3019 case XPATH_RANGE:
3020 xmlGenericError(xmlGenericErrorContext,
3021 "%s is a range\n", arg);
3022 break;
3023 case XPATH_LOCATIONSET:
3024 xmlGenericError(xmlGenericErrorContext,
3025 "%s is a range\n", arg);
3026 break;
3027 case XPATH_USERS:
3028 xmlGenericError(xmlGenericErrorContext,
3029 "%s is user-defined\n", arg);
3030 break;
3031 case XPATH_XSLT_TREE:
3032 xmlGenericError(xmlGenericErrorContext,
3033 "%s is an XSLT value tree\n",
3034 arg);
3035 break;
3036 }
3037#ifdef LIBXML_XPATH_ENABLED
3038 xmlXPathFreeObject(list);
3039#endif
3040 } else {
3041 xmlGenericError(xmlGenericErrorContext,
3042 "%s: no such node\n", arg);
3043 }
3044 ctxt->pctxt->node = NULL;
3045 }
Daniel Veillard78d12092001-10-11 09:12:24 +00003046 } else if (!strcmp(command, "base")) {
3047 xmlShellBase(ctxt, NULL, ctxt->node, NULL);
Daniel Veillard29b17482004-08-16 00:39:03 +00003048 } else if (!strcmp(command, "set")) {
3049 xmlShellSetContent(ctxt, arg, ctxt->node, NULL);
Daniel Veillard2070c482002-01-22 22:12:19 +00003050#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardbbaa9972004-06-16 14:08:33 +00003051 } else if (!strcmp(command, "setns")) {
3052 if (arg[0] == 0) {
3053 xmlGenericError(xmlGenericErrorContext,
3054 "setns: prefix=[nsuri] required\n");
3055 } else {
3056 xmlShellRegisterNamespace(ctxt, arg, NULL, NULL);
3057 }
Daniel Veillard20887ee2005-07-04 09:27:40 +00003058 } else if (!strcmp(command, "setrootns")) {
3059 xmlNodePtr root;
3060
3061 root = xmlDocGetRootElement(ctxt->doc);
3062 xmlShellRegisterRootNamespaces(ctxt, NULL, root, NULL);
Daniel Veillard2070c482002-01-22 22:12:19 +00003063 } else if (!strcmp(command, "xpath")) {
3064 if (arg[0] == 0) {
3065 xmlGenericError(xmlGenericErrorContext,
3066 "xpath: expression required\n");
3067 } else {
3068 ctxt->pctxt->node = ctxt->node;
3069 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Daniel Veillard321be0c2002-10-08 21:26:42 +00003070 xmlXPathDebugDumpObject(ctxt->output, list, 0);
Daniel Veillard2070c482002-01-22 22:12:19 +00003071 xmlXPathFreeObject(list);
3072 }
3073#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard2156d432004-03-04 15:59:36 +00003074#ifdef LIBXML_TREE_ENABLED
Daniel Veillardcfa0d812002-01-17 08:46:58 +00003075 } else if (!strcmp(command, "setbase")) {
3076 xmlShellSetBase(ctxt, arg, ctxt->node, NULL);
Daniel Veillard2156d432004-03-04 15:59:36 +00003077#endif
Daniel Veillard78d12092001-10-11 09:12:24 +00003078 } else if ((!strcmp(command, "ls")) || (!strcmp(command, "dir"))) {
3079 int dir = (!strcmp(command, "dir"));
3080
3081 if (arg[0] == 0) {
3082 if (dir)
3083 xmlShellDir(ctxt, NULL, ctxt->node, NULL);
3084 else
3085 xmlShellList(ctxt, NULL, ctxt->node, NULL);
3086 } else {
3087 ctxt->pctxt->node = ctxt->node;
Daniel Veillard61d80a22001-04-27 17:13:01 +00003088#ifdef LIBXML_XPATH_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00003089 ctxt->pctxt->node = ctxt->node;
3090 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3091#else
3092 list = NULL;
3093#endif /* LIBXML_XPATH_ENABLED */
3094 if (list != NULL) {
3095 switch (list->type) {
3096 case XPATH_UNDEFINED:
3097 xmlGenericError(xmlGenericErrorContext,
3098 "%s: no such node\n", arg);
3099 break;
3100 case XPATH_NODESET:{
3101 int indx;
3102
Daniel Veillarda6825e82001-11-07 13:33:59 +00003103 if (list->nodesetval == NULL)
3104 break;
3105
Daniel Veillard78d12092001-10-11 09:12:24 +00003106 for (indx = 0;
3107 indx < list->nodesetval->nodeNr;
3108 indx++) {
3109 if (dir)
3110 xmlShellDir(ctxt, NULL,
3111 list->nodesetval->
3112 nodeTab[indx], NULL);
3113 else
3114 xmlShellList(ctxt, NULL,
3115 list->nodesetval->
3116 nodeTab[indx], NULL);
3117 }
3118 break;
3119 }
3120 case XPATH_BOOLEAN:
3121 xmlGenericError(xmlGenericErrorContext,
3122 "%s is a Boolean\n", arg);
3123 break;
3124 case XPATH_NUMBER:
3125 xmlGenericError(xmlGenericErrorContext,
3126 "%s is a number\n", arg);
3127 break;
3128 case XPATH_STRING:
3129 xmlGenericError(xmlGenericErrorContext,
3130 "%s is a string\n", arg);
3131 break;
3132 case XPATH_POINT:
3133 xmlGenericError(xmlGenericErrorContext,
3134 "%s is a point\n", arg);
3135 break;
3136 case XPATH_RANGE:
3137 xmlGenericError(xmlGenericErrorContext,
3138 "%s is a range\n", arg);
3139 break;
3140 case XPATH_LOCATIONSET:
3141 xmlGenericError(xmlGenericErrorContext,
3142 "%s is a range\n", arg);
3143 break;
3144 case XPATH_USERS:
3145 xmlGenericError(xmlGenericErrorContext,
3146 "%s is user-defined\n", arg);
3147 break;
3148 case XPATH_XSLT_TREE:
3149 xmlGenericError(xmlGenericErrorContext,
3150 "%s is an XSLT value tree\n",
3151 arg);
3152 break;
3153 }
3154#ifdef LIBXML_XPATH_ENABLED
3155 xmlXPathFreeObject(list);
Daniel Veillard61d80a22001-04-27 17:13:01 +00003156#endif
Daniel Veillard78d12092001-10-11 09:12:24 +00003157 } else {
3158 xmlGenericError(xmlGenericErrorContext,
3159 "%s: no such node\n", arg);
3160 }
3161 ctxt->pctxt->node = NULL;
3162 }
Ryan0cd29a32012-05-07 19:53:19 +08003163 } else if (!strcmp(command, "whereis")) {
3164 char dir[500];
3165
3166 if (arg[0] == 0) {
3167 if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
3168 fprintf(ctxt->output, "%s\n", dir);
3169 } else {
3170 ctxt->pctxt->node = ctxt->node;
3171#ifdef LIBXML_XPATH_ENABLED
3172 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3173#else
3174 list = NULL;
3175#endif /* LIBXML_XPATH_ENABLED */
3176 if (list != NULL) {
3177 switch (list->type) {
3178 case XPATH_UNDEFINED:
3179 xmlGenericError(xmlGenericErrorContext,
3180 "%s: no such node\n", arg);
3181 break;
3182 case XPATH_NODESET:{
3183 int indx;
3184
3185 if (list->nodesetval == NULL)
3186 break;
3187
3188 for (indx = 0;
3189 indx < list->nodesetval->nodeNr;
3190 indx++) {
3191 if (!xmlShellPwd(ctxt, dir, list->nodesetval->
3192 nodeTab[indx], NULL))
3193 fprintf(ctxt->output, "%s\n", dir);
3194 }
3195 break;
3196 }
3197 case XPATH_BOOLEAN:
3198 xmlGenericError(xmlGenericErrorContext,
3199 "%s is a Boolean\n", arg);
3200 break;
3201 case XPATH_NUMBER:
3202 xmlGenericError(xmlGenericErrorContext,
3203 "%s is a number\n", arg);
3204 break;
3205 case XPATH_STRING:
3206 xmlGenericError(xmlGenericErrorContext,
3207 "%s is a string\n", arg);
3208 break;
3209 case XPATH_POINT:
3210 xmlGenericError(xmlGenericErrorContext,
3211 "%s is a point\n", arg);
3212 break;
3213 case XPATH_RANGE:
3214 xmlGenericError(xmlGenericErrorContext,
3215 "%s is a range\n", arg);
3216 break;
3217 case XPATH_LOCATIONSET:
3218 xmlGenericError(xmlGenericErrorContext,
3219 "%s is a range\n", arg);
3220 break;
3221 case XPATH_USERS:
3222 xmlGenericError(xmlGenericErrorContext,
3223 "%s is user-defined\n", arg);
3224 break;
3225 case XPATH_XSLT_TREE:
3226 xmlGenericError(xmlGenericErrorContext,
3227 "%s is an XSLT value tree\n",
3228 arg);
3229 break;
3230 }
3231#ifdef LIBXML_XPATH_ENABLED
3232 xmlXPathFreeObject(list);
3233#endif
3234 } else {
3235 xmlGenericError(xmlGenericErrorContext,
3236 "%s: no such node\n", arg);
3237 }
3238 ctxt->pctxt->node = NULL;
3239 }
Daniel Veillard78d12092001-10-11 09:12:24 +00003240 } else if (!strcmp(command, "cd")) {
3241 if (arg[0] == 0) {
3242 ctxt->node = (xmlNodePtr) ctxt->doc;
3243 } else {
3244#ifdef LIBXML_XPATH_ENABLED
3245 ctxt->pctxt->node = ctxt->node;
3246 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3247#else
3248 list = NULL;
3249#endif /* LIBXML_XPATH_ENABLED */
3250 if (list != NULL) {
3251 switch (list->type) {
3252 case XPATH_UNDEFINED:
3253 xmlGenericError(xmlGenericErrorContext,
3254 "%s: no such node\n", arg);
3255 break;
3256 case XPATH_NODESET:
Daniel Veillarda6825e82001-11-07 13:33:59 +00003257 if (list->nodesetval != NULL) {
3258 if (list->nodesetval->nodeNr == 1) {
3259 ctxt->node = list->nodesetval->nodeTab[0];
Daniel Veillard7a985a12003-07-06 17:57:42 +00003260 if ((ctxt->node != NULL) &&
3261 (ctxt->node->type ==
3262 XML_NAMESPACE_DECL)) {
3263 xmlGenericError(xmlGenericErrorContext,
3264 "cannot cd to namespace\n");
3265 ctxt->node = NULL;
3266 }
Daniel Veillarda6825e82001-11-07 13:33:59 +00003267 } else
3268 xmlGenericError(xmlGenericErrorContext,
3269 "%s is a %d Node Set\n",
3270 arg,
3271 list->nodesetval->nodeNr);
Daniel Veillard78d12092001-10-11 09:12:24 +00003272 } else
3273 xmlGenericError(xmlGenericErrorContext,
Daniel Veillarda6825e82001-11-07 13:33:59 +00003274 "%s is an empty Node Set\n",
3275 arg);
Daniel Veillard78d12092001-10-11 09:12:24 +00003276 break;
3277 case XPATH_BOOLEAN:
3278 xmlGenericError(xmlGenericErrorContext,
3279 "%s is a Boolean\n", arg);
3280 break;
3281 case XPATH_NUMBER:
3282 xmlGenericError(xmlGenericErrorContext,
3283 "%s is a number\n", arg);
3284 break;
3285 case XPATH_STRING:
3286 xmlGenericError(xmlGenericErrorContext,
3287 "%s is a string\n", arg);
3288 break;
3289 case XPATH_POINT:
3290 xmlGenericError(xmlGenericErrorContext,
3291 "%s is a point\n", arg);
3292 break;
3293 case XPATH_RANGE:
3294 xmlGenericError(xmlGenericErrorContext,
3295 "%s is a range\n", arg);
3296 break;
3297 case XPATH_LOCATIONSET:
3298 xmlGenericError(xmlGenericErrorContext,
3299 "%s is a range\n", arg);
3300 break;
3301 case XPATH_USERS:
3302 xmlGenericError(xmlGenericErrorContext,
3303 "%s is user-defined\n", arg);
3304 break;
3305 case XPATH_XSLT_TREE:
3306 xmlGenericError(xmlGenericErrorContext,
3307 "%s is an XSLT value tree\n",
3308 arg);
3309 break;
3310 }
3311#ifdef LIBXML_XPATH_ENABLED
3312 xmlXPathFreeObject(list);
3313#endif
3314 } else {
3315 xmlGenericError(xmlGenericErrorContext,
3316 "%s: no such node\n", arg);
3317 }
3318 ctxt->pctxt->node = NULL;
3319 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00003320#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard78d12092001-10-11 09:12:24 +00003321 } else if (!strcmp(command, "cat")) {
3322 if (arg[0] == 0) {
3323 xmlShellCat(ctxt, NULL, ctxt->node, NULL);
3324 } else {
3325 ctxt->pctxt->node = ctxt->node;
3326#ifdef LIBXML_XPATH_ENABLED
3327 ctxt->pctxt->node = ctxt->node;
3328 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3329#else
3330 list = NULL;
3331#endif /* LIBXML_XPATH_ENABLED */
3332 if (list != NULL) {
3333 switch (list->type) {
3334 case XPATH_UNDEFINED:
3335 xmlGenericError(xmlGenericErrorContext,
3336 "%s: no such node\n", arg);
3337 break;
3338 case XPATH_NODESET:{
3339 int indx;
3340
Daniel Veillarda6825e82001-11-07 13:33:59 +00003341 if (list->nodesetval == NULL)
3342 break;
3343
Daniel Veillard78d12092001-10-11 09:12:24 +00003344 for (indx = 0;
3345 indx < list->nodesetval->nodeNr;
3346 indx++) {
3347 if (i > 0)
Daniel Veillard321be0c2002-10-08 21:26:42 +00003348 fprintf(ctxt->output, " -------\n");
Daniel Veillard78d12092001-10-11 09:12:24 +00003349 xmlShellCat(ctxt, NULL,
3350 list->nodesetval->
3351 nodeTab[indx], NULL);
3352 }
3353 break;
3354 }
3355 case XPATH_BOOLEAN:
3356 xmlGenericError(xmlGenericErrorContext,
3357 "%s is a Boolean\n", arg);
3358 break;
3359 case XPATH_NUMBER:
3360 xmlGenericError(xmlGenericErrorContext,
3361 "%s is a number\n", arg);
3362 break;
3363 case XPATH_STRING:
3364 xmlGenericError(xmlGenericErrorContext,
3365 "%s is a string\n", arg);
3366 break;
3367 case XPATH_POINT:
3368 xmlGenericError(xmlGenericErrorContext,
3369 "%s is a point\n", arg);
3370 break;
3371 case XPATH_RANGE:
3372 xmlGenericError(xmlGenericErrorContext,
3373 "%s is a range\n", arg);
3374 break;
3375 case XPATH_LOCATIONSET:
3376 xmlGenericError(xmlGenericErrorContext,
3377 "%s is a range\n", arg);
3378 break;
3379 case XPATH_USERS:
3380 xmlGenericError(xmlGenericErrorContext,
3381 "%s is user-defined\n", arg);
3382 break;
3383 case XPATH_XSLT_TREE:
3384 xmlGenericError(xmlGenericErrorContext,
3385 "%s is an XSLT value tree\n",
3386 arg);
3387 break;
3388 }
3389#ifdef LIBXML_XPATH_ENABLED
3390 xmlXPathFreeObject(list);
3391#endif
3392 } else {
3393 xmlGenericError(xmlGenericErrorContext,
3394 "%s: no such node\n", arg);
3395 }
3396 ctxt->pctxt->node = NULL;
3397 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00003398#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard78d12092001-10-11 09:12:24 +00003399 } else {
3400 xmlGenericError(xmlGenericErrorContext,
3401 "Unknown command %s\n", command);
3402 }
3403 free(cmdline); /* not xmlFree here ! */
Daniel Veillard30663512008-02-21 22:31:55 +00003404 cmdline = NULL;
Owen Taylor3473f882001-02-23 17:55:21 +00003405 }
3406#ifdef LIBXML_XPATH_ENABLED
3407 xmlXPathFreeContext(ctxt->pctxt);
3408#endif /* LIBXML_XPATH_ENABLED */
3409 if (ctxt->loaded) {
3410 xmlFreeDoc(ctxt->doc);
3411 }
Daniel Veillardb8c9be92001-07-09 16:01:19 +00003412 if (ctxt->filename != NULL)
Daniel Veillard78d12092001-10-11 09:12:24 +00003413 xmlFree(ctxt->filename);
Owen Taylor3473f882001-02-23 17:55:21 +00003414 xmlFree(ctxt);
3415 if (cmdline != NULL)
Daniel Veillard78d12092001-10-11 09:12:24 +00003416 free(cmdline); /* not xmlFree here ! */
Owen Taylor3473f882001-02-23 17:55:21 +00003417}
3418
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00003419#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard5d4644e2005-04-01 13:11:58 +00003420#define bottom_debugXML
3421#include "elfgcchack.h"
Owen Taylor3473f882001-02-23 17:55:21 +00003422#endif /* LIBXML_DEBUG_ENABLED */