2 * debugXML.c : This is a set of routines used for debugging the tree
3 * produced by the XML parser.
5 * See Copyright for the status of this software.
7 * Daniel Veillard <daniel@veillard.com>
12 #ifdef LIBXML_DEBUG_ENABLED
21 #include <libxml/xmlmemory.h>
22 #include <libxml/tree.h>
23 #include <libxml/parser.h>
24 #include <libxml/parserInternals.h>
25 #include <libxml/valid.h>
26 #include <libxml/debugXML.h>
27 #include <libxml/HTMLtree.h>
28 #include <libxml/HTMLparser.h>
29 #include <libxml/xmlerror.h>
30 #include <libxml/globals.h>
31 #include <libxml/xpathInternals.h>
32 #include <libxml/uri.h>
33 #ifdef LIBXML_SCHEMAS_ENABLED
34 #include <libxml/relaxng.h>
37 #define DUMP_TEXT_TYPE 1
39 typedef struct _xmlDebugCtxt xmlDebugCtxt
;
40 typedef xmlDebugCtxt
*xmlDebugCtxtPtr
;
41 struct _xmlDebugCtxt
{
42 FILE *output
; /* the output file */
43 char shift
[101]; /* used for indenting */
44 int depth
; /* current depth */
45 xmlDocPtr doc
; /* current document */
46 xmlNodePtr node
; /* current node */
47 xmlDictPtr dict
; /* the doc dictionnary */
48 int check
; /* do just checkings */
49 int errors
; /* number of errors found */
50 int nodict
; /* if the document has no dictionnary */
51 int options
; /* options */
54 static void xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
);
57 xmlCtxtDumpInitCtxt(xmlDebugCtxtPtr ctxt
)
64 ctxt
->output
= stdout
;
70 for (i
= 0; i
< 100; i
++)
76 xmlCtxtDumpCleanCtxt(xmlDebugCtxtPtr ctxt ATTRIBUTE_UNUSED
)
78 /* remove the ATTRIBUTE_UNUSED when this is added */
84 * @ns: the namespace node
86 * Check that a given namespace is in scope on a node.
88 * Returns 1 if in scope, -1 in case of argument error,
89 * -2 if the namespace is not in scope, and -3 if not on
93 xmlNsCheckScope(xmlNodePtr node
, xmlNsPtr ns
)
97 if ((node
== NULL
) || (ns
== NULL
))
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
))
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
)) {
116 while (cur
!= NULL
) {
119 if (xmlStrEqual(cur
->prefix
, ns
->prefix
))
126 /* 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
;
138 xmlCtxtDumpSpaces(xmlDebugCtxtPtr ctxt
)
142 if ((ctxt
->output
!= NULL
) && (ctxt
->depth
> 0)) {
143 if (ctxt
->depth
< 50)
144 fprintf(ctxt
->output
, "%s", &ctxt
->shift
[100 - 2 * ctxt
->depth
]);
146 fprintf(ctxt
->output
, "%s", ctxt
->shift
);
152 * @ctxt: a debug context
153 * @error: the error code
155 * Handle a debug error.
158 xmlDebugErr(xmlDebugCtxtPtr ctxt
, int error
, const char *msg
)
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,
168 xmlDebugErr2(xmlDebugCtxtPtr ctxt
, int error
, const char *msg
, int extra
)
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,
178 xmlDebugErr3(xmlDebugCtxtPtr ctxt
, int error
, const char *msg
, const char *extra
)
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,
189 * xmlCtxtNsCheckScope:
190 * @ctxt: the debugging context
192 * @ns: the namespace node
194 * Report if a given namespace is is not in scope.
197 xmlCtxtNsCheckScope(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
, xmlNsPtr ns
)
201 ret
= xmlNsCheckScope(node
, ns
);
203 if (ns
->prefix
== NULL
)
204 xmlDebugErr(ctxt
, XML_CHECK_NS_SCOPE
,
205 "Reference to default namespace not in scope\n");
207 xmlDebugErr3(ctxt
, XML_CHECK_NS_SCOPE
,
208 "Reference to namespace '%s' not in scope\n",
209 (char *) ns
->prefix
);
212 if (ns
->prefix
== NULL
)
213 xmlDebugErr(ctxt
, XML_CHECK_NS_ANCESTOR
,
214 "Reference to default namespace not on ancestor\n");
216 xmlDebugErr3(ctxt
, XML_CHECK_NS_ANCESTOR
,
217 "Reference to namespace '%s' not on ancestor\n",
218 (char *) ns
->prefix
);
223 * xmlCtxtCheckString:
224 * @ctxt: the debug context
227 * Do debugging on the string, currently it just checks the UTF-8 content
230 xmlCtxtCheckString(xmlDebugCtxtPtr ctxt
, const xmlChar
* str
)
232 if (str
== NULL
) return;
234 if (!xmlCheckUTF8(str
)) {
235 xmlDebugErr3(ctxt
, XML_CHECK_NOT_UTF8
,
236 "String is not UTF-8 %s", (const char *) str
);
243 * @ctxt: the debug context
246 * Do debugging on the name, for example the dictionnary status and
247 * conformance to the Name production.
250 xmlCtxtCheckName(xmlDebugCtxtPtr ctxt
, const xmlChar
* name
)
254 xmlDebugErr(ctxt
, XML_CHECK_NO_NAME
, "Name is NULL");
257 if (xmlValidateName(name
, 0)) {
258 xmlDebugErr3(ctxt
, XML_CHECK_NOT_NCNAME
,
259 "Name is not an NCName '%s'", (const char *) name
);
261 if ((ctxt
->dict
!= NULL
) &&
262 (!xmlDictOwns(ctxt
->dict
, name
)) &&
263 ((ctxt
->doc
== NULL
) ||
264 ((ctxt
->doc
->parseFlags
& (XML_PARSE_SAX1
| XML_PARSE_NODICT
)) == 0))) {
265 xmlDebugErr3(ctxt
, XML_CHECK_OUTSIDE_DICT
,
266 "Name is not from the document dictionnary '%s'",
267 (const char *) name
);
273 xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
) {
279 if (node
->parent
== NULL
)
280 xmlDebugErr(ctxt
, XML_CHECK_NO_PARENT
,
281 "Node has no parent\n");
282 if (node
->doc
== NULL
) {
283 xmlDebugErr(ctxt
, XML_CHECK_NO_DOC
,
284 "Node has no doc\n");
288 if ((dict
== NULL
) && (ctxt
->nodict
== 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");
297 if (ctxt
->doc
== NULL
)
300 if (ctxt
->dict
== NULL
) {
304 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");
315 } 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");
319 if (node
->prev
->next
!= node
)
320 xmlDebugErr(ctxt
, XML_CHECK_WRONG_PREV
,
321 "Node prev->next : back link wrong\n");
323 if (node
->next
== NULL
) {
324 if ((node
->parent
!= NULL
) && (node
->type
!= XML_ATTRIBUTE_NODE
) &&
325 (node
->parent
->last
!= node
) &&
326 (node
->parent
->type
== XML_ELEMENT_NODE
))
327 xmlDebugErr(ctxt
, XML_CHECK_NO_NEXT
,
328 "Node has no next and not last of parent list\n");
330 if (node
->next
->prev
!= node
)
331 xmlDebugErr(ctxt
, XML_CHECK_WRONG_NEXT
,
332 "Node next->prev : forward link wrong\n");
333 if (node
->next
->parent
!= node
->parent
)
334 xmlDebugErr(ctxt
, XML_CHECK_WRONG_PARENT
,
335 "Node next->prev : forward link wrong\n");
337 if (node
->type
== XML_ELEMENT_NODE
) {
342 xmlCtxtNsCheckScope(ctxt
, node
, ns
);
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
);
352 if ((node
->type
!= XML_ELEMENT_NODE
) &&
353 (node
->type
!= XML_ATTRIBUTE_NODE
) &&
354 (node
->type
!= XML_ELEMENT_DECL
) &&
355 (node
->type
!= XML_ATTRIBUTE_DECL
) &&
356 (node
->type
!= XML_DTD_NODE
) &&
357 (node
->type
!= XML_HTML_DOCUMENT_NODE
) &&
358 (node
->type
!= XML_DOCUMENT_NODE
)) {
359 if (node
->content
!= NULL
)
360 xmlCtxtCheckString(ctxt
, (const xmlChar
*) node
->content
);
362 switch (node
->type
) {
363 case XML_ELEMENT_NODE
:
364 case XML_ATTRIBUTE_NODE
:
365 xmlCtxtCheckName(ctxt
, node
->name
);
368 if ((node
->name
== xmlStringText
) ||
369 (node
->name
== xmlStringTextNoenc
))
371 /* some case of entity substitution can lead to this */
372 if ((ctxt
->dict
!= NULL
) &&
373 (node
->name
== xmlDictLookup(ctxt
->dict
, BAD_CAST
"nbktext",
377 xmlDebugErr3(ctxt
, XML_CHECK_WRONG_NAME
,
378 "Text node has wrong name '%s'",
379 (const char *) node
->name
);
381 case XML_COMMENT_NODE
:
382 if (node
->name
== xmlStringComment
)
384 xmlDebugErr3(ctxt
, XML_CHECK_WRONG_NAME
,
385 "Comment node has wrong name '%s'",
386 (const char *) node
->name
);
389 xmlCtxtCheckName(ctxt
, node
->name
);
391 case XML_CDATA_SECTION_NODE
:
392 if (node
->name
== NULL
)
394 xmlDebugErr3(ctxt
, XML_CHECK_NAME_NOT_NULL
,
395 "CData section has non NULL name '%s'",
396 (const char *) node
->name
);
398 case XML_ENTITY_REF_NODE
:
399 case XML_ENTITY_NODE
:
400 case XML_DOCUMENT_TYPE_NODE
:
401 case XML_DOCUMENT_FRAG_NODE
:
402 case XML_NOTATION_NODE
:
404 case XML_ELEMENT_DECL
:
405 case XML_ATTRIBUTE_DECL
:
406 case XML_ENTITY_DECL
:
407 case XML_NAMESPACE_DECL
:
408 case XML_XINCLUDE_START
:
409 case XML_XINCLUDE_END
:
410 #ifdef LIBXML_DOCB_ENABLED
411 case XML_DOCB_DOCUMENT_NODE
:
413 case XML_DOCUMENT_NODE
:
414 case XML_HTML_DOCUMENT_NODE
:
420 xmlCtxtDumpString(xmlDebugCtxtPtr ctxt
, const xmlChar
* str
)
427 /* TODO: check UTF8 content of the string */
429 fprintf(ctxt
->output
, "(NULL)");
432 for (i
= 0; i
< 40; i
++)
435 else if (IS_BLANK_CH(str
[i
]))
436 fputc(' ', ctxt
->output
);
437 else if (str
[i
] >= 0x80)
438 fprintf(ctxt
->output
, "#%X", str
[i
]);
440 fputc(str
[i
], ctxt
->output
);
441 fprintf(ctxt
->output
, "...");
445 xmlCtxtDumpDtdNode(xmlDebugCtxtPtr ctxt
, xmlDtdPtr dtd
)
447 xmlCtxtDumpSpaces(ctxt
);
451 fprintf(ctxt
->output
, "DTD node is NULL\n");
455 if (dtd
->type
!= XML_DTD_NODE
) {
456 xmlDebugErr(ctxt
, XML_CHECK_NOT_DTD
,
457 "Node is not a DTD");
461 if (dtd
->name
!= NULL
)
462 fprintf(ctxt
->output
, "DTD(%s)", (char *) dtd
->name
);
464 fprintf(ctxt
->output
, "DTD");
465 if (dtd
->ExternalID
!= NULL
)
466 fprintf(ctxt
->output
, ", PUBLIC %s", (char *) dtd
->ExternalID
);
467 if (dtd
->SystemID
!= NULL
)
468 fprintf(ctxt
->output
, ", SYSTEM %s", (char *) dtd
->SystemID
);
469 fprintf(ctxt
->output
, "\n");
472 * Do a bit of checking
474 xmlCtxtGenericNodeCheck(ctxt
, (xmlNodePtr
) dtd
);
478 xmlCtxtDumpAttrDecl(xmlDebugCtxtPtr ctxt
, xmlAttributePtr attr
)
480 xmlCtxtDumpSpaces(ctxt
);
484 fprintf(ctxt
->output
, "Attribute declaration is NULL\n");
487 if (attr
->type
!= XML_ATTRIBUTE_DECL
) {
488 xmlDebugErr(ctxt
, XML_CHECK_NOT_ATTR_DECL
,
489 "Node is not an attribute declaration");
492 if (attr
->name
!= NULL
) {
494 fprintf(ctxt
->output
, "ATTRDECL(%s)", (char *) attr
->name
);
496 xmlDebugErr(ctxt
, XML_CHECK_NO_NAME
,
497 "Node attribute declaration has no name");
498 if (attr
->elem
!= NULL
) {
500 fprintf(ctxt
->output
, " for %s", (char *) attr
->elem
);
502 xmlDebugErr(ctxt
, XML_CHECK_NO_ELEM
,
503 "Node attribute declaration has no element name");
505 switch (attr
->atype
) {
506 case XML_ATTRIBUTE_CDATA
:
507 fprintf(ctxt
->output
, " CDATA");
509 case XML_ATTRIBUTE_ID
:
510 fprintf(ctxt
->output
, " ID");
512 case XML_ATTRIBUTE_IDREF
:
513 fprintf(ctxt
->output
, " IDREF");
515 case XML_ATTRIBUTE_IDREFS
:
516 fprintf(ctxt
->output
, " IDREFS");
518 case XML_ATTRIBUTE_ENTITY
:
519 fprintf(ctxt
->output
, " ENTITY");
521 case XML_ATTRIBUTE_ENTITIES
:
522 fprintf(ctxt
->output
, " ENTITIES");
524 case XML_ATTRIBUTE_NMTOKEN
:
525 fprintf(ctxt
->output
, " NMTOKEN");
527 case XML_ATTRIBUTE_NMTOKENS
:
528 fprintf(ctxt
->output
, " NMTOKENS");
530 case XML_ATTRIBUTE_ENUMERATION
:
531 fprintf(ctxt
->output
, " ENUMERATION");
533 case XML_ATTRIBUTE_NOTATION
:
534 fprintf(ctxt
->output
, " NOTATION ");
537 if (attr
->tree
!= NULL
) {
539 xmlEnumerationPtr cur
= attr
->tree
;
541 for (indx
= 0; indx
< 5; indx
++) {
543 fprintf(ctxt
->output
, "|%s", (char *) cur
->name
);
545 fprintf(ctxt
->output
, " (%s", (char *) cur
->name
);
551 fprintf(ctxt
->output
, ")");
553 fprintf(ctxt
->output
, "...)");
556 case XML_ATTRIBUTE_NONE
:
558 case XML_ATTRIBUTE_REQUIRED
:
559 fprintf(ctxt
->output
, " REQUIRED");
561 case XML_ATTRIBUTE_IMPLIED
:
562 fprintf(ctxt
->output
, " IMPLIED");
564 case XML_ATTRIBUTE_FIXED
:
565 fprintf(ctxt
->output
, " FIXED");
568 if (attr
->defaultValue
!= NULL
) {
569 fprintf(ctxt
->output
, "\"");
570 xmlCtxtDumpString(ctxt
, attr
->defaultValue
);
571 fprintf(ctxt
->output
, "\"");
573 fprintf(ctxt
->output
, "\n");
577 * Do a bit of checking
579 xmlCtxtGenericNodeCheck(ctxt
, (xmlNodePtr
) attr
);
583 xmlCtxtDumpElemDecl(xmlDebugCtxtPtr ctxt
, xmlElementPtr elem
)
585 xmlCtxtDumpSpaces(ctxt
);
589 fprintf(ctxt
->output
, "Element declaration is NULL\n");
592 if (elem
->type
!= XML_ELEMENT_DECL
) {
593 xmlDebugErr(ctxt
, XML_CHECK_NOT_ELEM_DECL
,
594 "Node is not an element declaration");
597 if (elem
->name
!= NULL
) {
599 fprintf(ctxt
->output
, "ELEMDECL(");
600 xmlCtxtDumpString(ctxt
, elem
->name
);
601 fprintf(ctxt
->output
, ")");
604 xmlDebugErr(ctxt
, XML_CHECK_NO_NAME
,
605 "Element declaration has no name");
607 switch (elem
->etype
) {
608 case XML_ELEMENT_TYPE_UNDEFINED
:
609 fprintf(ctxt
->output
, ", UNDEFINED");
611 case XML_ELEMENT_TYPE_EMPTY
:
612 fprintf(ctxt
->output
, ", EMPTY");
614 case XML_ELEMENT_TYPE_ANY
:
615 fprintf(ctxt
->output
, ", ANY");
617 case XML_ELEMENT_TYPE_MIXED
:
618 fprintf(ctxt
->output
, ", MIXED ");
620 case XML_ELEMENT_TYPE_ELEMENT
:
621 fprintf(ctxt
->output
, ", MIXED ");
624 if ((elem
->type
!= XML_ELEMENT_NODE
) && (elem
->content
!= NULL
)) {
628 xmlSnprintfElementContent(buf
, 5000, elem
->content
, 1);
630 fprintf(ctxt
->output
, "%s", buf
);
632 fprintf(ctxt
->output
, "\n");
636 * Do a bit of checking
638 xmlCtxtGenericNodeCheck(ctxt
, (xmlNodePtr
) elem
);
642 xmlCtxtDumpEntityDecl(xmlDebugCtxtPtr ctxt
, xmlEntityPtr ent
)
644 xmlCtxtDumpSpaces(ctxt
);
648 fprintf(ctxt
->output
, "Entity declaration is NULL\n");
651 if (ent
->type
!= XML_ENTITY_DECL
) {
652 xmlDebugErr(ctxt
, XML_CHECK_NOT_ENTITY_DECL
,
653 "Node is not an entity declaration");
656 if (ent
->name
!= NULL
) {
658 fprintf(ctxt
->output
, "ENTITYDECL(");
659 xmlCtxtDumpString(ctxt
, ent
->name
);
660 fprintf(ctxt
->output
, ")");
663 xmlDebugErr(ctxt
, XML_CHECK_NO_NAME
,
664 "Entity declaration has no name");
666 switch (ent
->etype
) {
667 case XML_INTERNAL_GENERAL_ENTITY
:
668 fprintf(ctxt
->output
, ", internal\n");
670 case XML_EXTERNAL_GENERAL_PARSED_ENTITY
:
671 fprintf(ctxt
->output
, ", external parsed\n");
673 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
:
674 fprintf(ctxt
->output
, ", unparsed\n");
676 case XML_INTERNAL_PARAMETER_ENTITY
:
677 fprintf(ctxt
->output
, ", parameter\n");
679 case XML_EXTERNAL_PARAMETER_ENTITY
:
680 fprintf(ctxt
->output
, ", external parameter\n");
682 case XML_INTERNAL_PREDEFINED_ENTITY
:
683 fprintf(ctxt
->output
, ", predefined\n");
686 if (ent
->ExternalID
) {
687 xmlCtxtDumpSpaces(ctxt
);
688 fprintf(ctxt
->output
, " ExternalID=%s\n",
689 (char *) ent
->ExternalID
);
692 xmlCtxtDumpSpaces(ctxt
);
693 fprintf(ctxt
->output
, " SystemID=%s\n",
694 (char *) ent
->SystemID
);
696 if (ent
->URI
!= NULL
) {
697 xmlCtxtDumpSpaces(ctxt
);
698 fprintf(ctxt
->output
, " URI=%s\n", (char *) ent
->URI
);
701 xmlCtxtDumpSpaces(ctxt
);
702 fprintf(ctxt
->output
, " content=");
703 xmlCtxtDumpString(ctxt
, ent
->content
);
704 fprintf(ctxt
->output
, "\n");
709 * Do a bit of checking
711 xmlCtxtGenericNodeCheck(ctxt
, (xmlNodePtr
) ent
);
715 xmlCtxtDumpNamespace(xmlDebugCtxtPtr ctxt
, xmlNsPtr ns
)
717 xmlCtxtDumpSpaces(ctxt
);
721 fprintf(ctxt
->output
, "namespace node is NULL\n");
724 if (ns
->type
!= XML_NAMESPACE_DECL
) {
725 xmlDebugErr(ctxt
, XML_CHECK_NOT_NS_DECL
,
726 "Node is not a namespace declaration");
729 if (ns
->href
== NULL
) {
730 if (ns
->prefix
!= NULL
)
731 xmlDebugErr3(ctxt
, XML_CHECK_NO_HREF
,
732 "Incomplete namespace %s href=NULL\n",
733 (char *) ns
->prefix
);
735 xmlDebugErr(ctxt
, XML_CHECK_NO_HREF
,
736 "Incomplete default namespace href=NULL\n");
739 if (ns
->prefix
!= NULL
)
740 fprintf(ctxt
->output
, "namespace %s href=",
741 (char *) ns
->prefix
);
743 fprintf(ctxt
->output
, "default namespace href=");
745 xmlCtxtDumpString(ctxt
, ns
->href
);
746 fprintf(ctxt
->output
, "\n");
752 xmlCtxtDumpNamespaceList(xmlDebugCtxtPtr ctxt
, xmlNsPtr ns
)
755 xmlCtxtDumpNamespace(ctxt
, ns
);
761 xmlCtxtDumpEntity(xmlDebugCtxtPtr ctxt
, xmlEntityPtr ent
)
763 xmlCtxtDumpSpaces(ctxt
);
767 fprintf(ctxt
->output
, "Entity is NULL\n");
771 switch (ent
->etype
) {
772 case XML_INTERNAL_GENERAL_ENTITY
:
773 fprintf(ctxt
->output
, "INTERNAL_GENERAL_ENTITY ");
775 case XML_EXTERNAL_GENERAL_PARSED_ENTITY
:
776 fprintf(ctxt
->output
, "EXTERNAL_GENERAL_PARSED_ENTITY ");
778 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
:
779 fprintf(ctxt
->output
, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");
781 case XML_INTERNAL_PARAMETER_ENTITY
:
782 fprintf(ctxt
->output
, "INTERNAL_PARAMETER_ENTITY ");
784 case XML_EXTERNAL_PARAMETER_ENTITY
:
785 fprintf(ctxt
->output
, "EXTERNAL_PARAMETER_ENTITY ");
788 fprintf(ctxt
->output
, "ENTITY_%d ! ", (int) ent
->etype
);
790 fprintf(ctxt
->output
, "%s\n", ent
->name
);
791 if (ent
->ExternalID
) {
792 xmlCtxtDumpSpaces(ctxt
);
793 fprintf(ctxt
->output
, "ExternalID=%s\n",
794 (char *) ent
->ExternalID
);
797 xmlCtxtDumpSpaces(ctxt
);
798 fprintf(ctxt
->output
, "SystemID=%s\n", (char *) ent
->SystemID
);
801 xmlCtxtDumpSpaces(ctxt
);
802 fprintf(ctxt
->output
, "URI=%s\n", (char *) ent
->URI
);
805 xmlCtxtDumpSpaces(ctxt
);
806 fprintf(ctxt
->output
, "content=");
807 xmlCtxtDumpString(ctxt
, ent
->content
);
808 fprintf(ctxt
->output
, "\n");
815 * @output: the FILE * for the output
816 * @attr: the attribute
817 * @depth: the indentation level.
819 * Dumps debug information for the attribute
822 xmlCtxtDumpAttr(xmlDebugCtxtPtr ctxt
, xmlAttrPtr attr
)
824 xmlCtxtDumpSpaces(ctxt
);
828 fprintf(ctxt
->output
, "Attr is NULL");
832 fprintf(ctxt
->output
, "ATTRIBUTE ");
833 xmlCtxtDumpString(ctxt
, attr
->name
);
834 fprintf(ctxt
->output
, "\n");
835 if (attr
->children
!= NULL
) {
837 xmlCtxtDumpNodeList(ctxt
, attr
->children
);
841 if (attr
->name
== NULL
)
842 xmlDebugErr(ctxt
, XML_CHECK_NO_NAME
,
843 "Attribute has no name");
846 * Do a bit of checking
848 xmlCtxtGenericNodeCheck(ctxt
, (xmlNodePtr
) attr
);
852 * xmlCtxtDumpAttrList:
853 * @output: the FILE * for the output
854 * @attr: the attribute list
855 * @depth: the indentation level.
857 * Dumps debug information for the attribute list
860 xmlCtxtDumpAttrList(xmlDebugCtxtPtr ctxt
, xmlAttrPtr attr
)
862 while (attr
!= NULL
) {
863 xmlCtxtDumpAttr(ctxt
, attr
);
869 * xmlCtxtDumpOneNode:
870 * @output: the FILE * for the output
872 * @depth: the indentation level.
874 * Dumps debug information for the element node, it is not recursive
877 xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
)
881 xmlCtxtDumpSpaces(ctxt
);
882 fprintf(ctxt
->output
, "node is NULL\n");
888 switch (node
->type
) {
889 case XML_ELEMENT_NODE
:
891 xmlCtxtDumpSpaces(ctxt
);
892 fprintf(ctxt
->output
, "ELEMENT ");
893 if ((node
->ns
!= NULL
) && (node
->ns
->prefix
!= NULL
)) {
894 xmlCtxtDumpString(ctxt
, node
->ns
->prefix
);
895 fprintf(ctxt
->output
, ":");
897 xmlCtxtDumpString(ctxt
, node
->name
);
898 fprintf(ctxt
->output
, "\n");
901 case XML_ATTRIBUTE_NODE
:
903 xmlCtxtDumpSpaces(ctxt
);
904 fprintf(ctxt
->output
, "Error, ATTRIBUTE found here\n");
905 xmlCtxtGenericNodeCheck(ctxt
, node
);
909 xmlCtxtDumpSpaces(ctxt
);
910 if (node
->name
== (const xmlChar
*) xmlStringTextNoenc
)
911 fprintf(ctxt
->output
, "TEXT no enc");
913 fprintf(ctxt
->output
, "TEXT");
914 if (ctxt
->options
& DUMP_TEXT_TYPE
) {
915 if (node
->content
== (xmlChar
*) &(node
->properties
))
916 fprintf(ctxt
->output
, " compact\n");
917 else if (xmlDictOwns(ctxt
->dict
, node
->content
) == 1)
918 fprintf(ctxt
->output
, " interned\n");
920 fprintf(ctxt
->output
, "\n");
922 fprintf(ctxt
->output
, "\n");
925 case XML_CDATA_SECTION_NODE
:
927 xmlCtxtDumpSpaces(ctxt
);
928 fprintf(ctxt
->output
, "CDATA_SECTION\n");
931 case XML_ENTITY_REF_NODE
:
933 xmlCtxtDumpSpaces(ctxt
);
934 fprintf(ctxt
->output
, "ENTITY_REF(%s)\n",
935 (char *) node
->name
);
938 case XML_ENTITY_NODE
:
940 xmlCtxtDumpSpaces(ctxt
);
941 fprintf(ctxt
->output
, "ENTITY\n");
946 xmlCtxtDumpSpaces(ctxt
);
947 fprintf(ctxt
->output
, "PI %s\n", (char *) node
->name
);
950 case XML_COMMENT_NODE
:
952 xmlCtxtDumpSpaces(ctxt
);
953 fprintf(ctxt
->output
, "COMMENT\n");
956 case XML_DOCUMENT_NODE
:
957 case XML_HTML_DOCUMENT_NODE
:
959 xmlCtxtDumpSpaces(ctxt
);
961 fprintf(ctxt
->output
, "Error, DOCUMENT found here\n");
962 xmlCtxtGenericNodeCheck(ctxt
, node
);
964 case XML_DOCUMENT_TYPE_NODE
:
966 xmlCtxtDumpSpaces(ctxt
);
967 fprintf(ctxt
->output
, "DOCUMENT_TYPE\n");
970 case XML_DOCUMENT_FRAG_NODE
:
972 xmlCtxtDumpSpaces(ctxt
);
973 fprintf(ctxt
->output
, "DOCUMENT_FRAG\n");
976 case XML_NOTATION_NODE
:
978 xmlCtxtDumpSpaces(ctxt
);
979 fprintf(ctxt
->output
, "NOTATION\n");
983 xmlCtxtDumpDtdNode(ctxt
, (xmlDtdPtr
) node
);
985 case XML_ELEMENT_DECL
:
986 xmlCtxtDumpElemDecl(ctxt
, (xmlElementPtr
) node
);
988 case XML_ATTRIBUTE_DECL
:
989 xmlCtxtDumpAttrDecl(ctxt
, (xmlAttributePtr
) node
);
991 case XML_ENTITY_DECL
:
992 xmlCtxtDumpEntityDecl(ctxt
, (xmlEntityPtr
) node
);
994 case XML_NAMESPACE_DECL
:
995 xmlCtxtDumpNamespace(ctxt
, (xmlNsPtr
) node
);
997 case XML_XINCLUDE_START
:
999 xmlCtxtDumpSpaces(ctxt
);
1000 fprintf(ctxt
->output
, "INCLUDE START\n");
1003 case XML_XINCLUDE_END
:
1005 xmlCtxtDumpSpaces(ctxt
);
1006 fprintf(ctxt
->output
, "INCLUDE END\n");
1011 xmlCtxtDumpSpaces(ctxt
);
1012 xmlDebugErr2(ctxt
, XML_CHECK_UNKNOWN_NODE
,
1013 "Unknown node type %d\n", node
->type
);
1016 if (node
->doc
== NULL
) {
1018 xmlCtxtDumpSpaces(ctxt
);
1020 fprintf(ctxt
->output
, "PBM: doc == NULL !!!\n");
1023 if ((node
->type
== XML_ELEMENT_NODE
) && (node
->nsDef
!= NULL
))
1024 xmlCtxtDumpNamespaceList(ctxt
, node
->nsDef
);
1025 if ((node
->type
== XML_ELEMENT_NODE
) && (node
->properties
!= NULL
))
1026 xmlCtxtDumpAttrList(ctxt
, node
->properties
);
1027 if (node
->type
!= XML_ENTITY_REF_NODE
) {
1028 if ((node
->type
!= XML_ELEMENT_NODE
) && (node
->content
!= NULL
)) {
1030 xmlCtxtDumpSpaces(ctxt
);
1031 fprintf(ctxt
->output
, "content=");
1032 xmlCtxtDumpString(ctxt
, node
->content
);
1033 fprintf(ctxt
->output
, "\n");
1039 ent
= xmlGetDocEntity(node
->doc
, node
->name
);
1041 xmlCtxtDumpEntity(ctxt
, ent
);
1046 * Do a bit of checking
1048 xmlCtxtGenericNodeCheck(ctxt
, node
);
1053 * @output: the FILE * for the output
1055 * @depth: the indentation level.
1057 * Dumps debug information for the element node, it is recursive
1060 xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
)
1064 xmlCtxtDumpSpaces(ctxt
);
1065 fprintf(ctxt
->output
, "node is NULL\n");
1069 xmlCtxtDumpOneNode(ctxt
, node
);
1070 if ((node
->type
!= XML_NAMESPACE_DECL
) &&
1071 (node
->children
!= NULL
) && (node
->type
!= XML_ENTITY_REF_NODE
)) {
1073 xmlCtxtDumpNodeList(ctxt
, node
->children
);
1079 * xmlCtxtDumpNodeList:
1080 * @output: the FILE * for the output
1081 * @node: the node list
1082 * @depth: the indentation level.
1084 * Dumps debug information for the list of element node, it is recursive
1087 xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt
, xmlNodePtr node
)
1089 while (node
!= NULL
) {
1090 xmlCtxtDumpNode(ctxt
, node
);
1096 xmlCtxtDumpDocHead(xmlDebugCtxtPtr ctxt
, xmlDocPtr doc
)
1100 fprintf(ctxt
->output
, "DOCUMENT == NULL !\n");
1103 ctxt
->node
= (xmlNodePtr
) doc
;
1105 switch (doc
->type
) {
1106 case XML_ELEMENT_NODE
:
1107 xmlDebugErr(ctxt
, XML_CHECK_FOUND_ELEMENT
,
1108 "Misplaced ELEMENT node\n");
1110 case XML_ATTRIBUTE_NODE
:
1111 xmlDebugErr(ctxt
, XML_CHECK_FOUND_ATTRIBUTE
,
1112 "Misplaced ATTRIBUTE node\n");
1115 xmlDebugErr(ctxt
, XML_CHECK_FOUND_TEXT
,
1116 "Misplaced TEXT node\n");
1118 case XML_CDATA_SECTION_NODE
:
1119 xmlDebugErr(ctxt
, XML_CHECK_FOUND_CDATA
,
1120 "Misplaced CDATA node\n");
1122 case XML_ENTITY_REF_NODE
:
1123 xmlDebugErr(ctxt
, XML_CHECK_FOUND_ENTITYREF
,
1124 "Misplaced ENTITYREF node\n");
1126 case XML_ENTITY_NODE
:
1127 xmlDebugErr(ctxt
, XML_CHECK_FOUND_ENTITY
,
1128 "Misplaced ENTITY node\n");
1131 xmlDebugErr(ctxt
, XML_CHECK_FOUND_PI
,
1132 "Misplaced PI node\n");
1134 case XML_COMMENT_NODE
:
1135 xmlDebugErr(ctxt
, XML_CHECK_FOUND_COMMENT
,
1136 "Misplaced COMMENT node\n");
1138 case XML_DOCUMENT_NODE
:
1140 fprintf(ctxt
->output
, "DOCUMENT\n");
1142 case XML_HTML_DOCUMENT_NODE
:
1144 fprintf(ctxt
->output
, "HTML DOCUMENT\n");
1146 case XML_DOCUMENT_TYPE_NODE
:
1147 xmlDebugErr(ctxt
, XML_CHECK_FOUND_DOCTYPE
,
1148 "Misplaced DOCTYPE node\n");
1150 case XML_DOCUMENT_FRAG_NODE
:
1151 xmlDebugErr(ctxt
, XML_CHECK_FOUND_FRAGMENT
,
1152 "Misplaced FRAGMENT node\n");
1154 case XML_NOTATION_NODE
:
1155 xmlDebugErr(ctxt
, XML_CHECK_FOUND_NOTATION
,
1156 "Misplaced NOTATION node\n");
1159 xmlDebugErr2(ctxt
, XML_CHECK_UNKNOWN_NODE
,
1160 "Unknown node type %d\n", doc
->type
);
1165 * xmlCtxtDumpDocumentHead:
1166 * @output: the FILE * for the output
1167 * @doc: the document
1169 * Dumps debug information cncerning the document, not recursive
1172 xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt
, xmlDocPtr doc
)
1174 if (doc
== NULL
) return;
1175 xmlCtxtDumpDocHead(ctxt
, doc
);
1177 if (doc
->name
!= NULL
) {
1178 fprintf(ctxt
->output
, "name=");
1179 xmlCtxtDumpString(ctxt
, BAD_CAST doc
->name
);
1180 fprintf(ctxt
->output
, "\n");
1182 if (doc
->version
!= NULL
) {
1183 fprintf(ctxt
->output
, "version=");
1184 xmlCtxtDumpString(ctxt
, doc
->version
);
1185 fprintf(ctxt
->output
, "\n");
1187 if (doc
->encoding
!= NULL
) {
1188 fprintf(ctxt
->output
, "encoding=");
1189 xmlCtxtDumpString(ctxt
, doc
->encoding
);
1190 fprintf(ctxt
->output
, "\n");
1192 if (doc
->URL
!= NULL
) {
1193 fprintf(ctxt
->output
, "URL=");
1194 xmlCtxtDumpString(ctxt
, doc
->URL
);
1195 fprintf(ctxt
->output
, "\n");
1197 if (doc
->standalone
)
1198 fprintf(ctxt
->output
, "standalone=true\n");
1200 if (doc
->oldNs
!= NULL
)
1201 xmlCtxtDumpNamespaceList(ctxt
, doc
->oldNs
);
1205 * xmlCtxtDumpDocument:
1206 * @output: the FILE * for the output
1207 * @doc: the document
1209 * Dumps debug information for the document, it's recursive
1212 xmlCtxtDumpDocument(xmlDebugCtxtPtr ctxt
, xmlDocPtr doc
)
1216 fprintf(ctxt
->output
, "DOCUMENT == NULL !\n");
1219 xmlCtxtDumpDocumentHead(ctxt
, doc
);
1220 if (((doc
->type
== XML_DOCUMENT_NODE
) ||
1221 (doc
->type
== XML_HTML_DOCUMENT_NODE
))
1222 && (doc
->children
!= NULL
)) {
1224 xmlCtxtDumpNodeList(ctxt
, doc
->children
);
1230 xmlCtxtDumpEntityCallback(xmlEntityPtr cur
, xmlDebugCtxtPtr ctxt
)
1234 fprintf(ctxt
->output
, "Entity is NULL");
1238 fprintf(ctxt
->output
, "%s : ", (char *) cur
->name
);
1239 switch (cur
->etype
) {
1240 case XML_INTERNAL_GENERAL_ENTITY
:
1241 fprintf(ctxt
->output
, "INTERNAL GENERAL, ");
1243 case XML_EXTERNAL_GENERAL_PARSED_ENTITY
:
1244 fprintf(ctxt
->output
, "EXTERNAL PARSED, ");
1246 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
:
1247 fprintf(ctxt
->output
, "EXTERNAL UNPARSED, ");
1249 case XML_INTERNAL_PARAMETER_ENTITY
:
1250 fprintf(ctxt
->output
, "INTERNAL PARAMETER, ");
1252 case XML_EXTERNAL_PARAMETER_ENTITY
:
1253 fprintf(ctxt
->output
, "EXTERNAL PARAMETER, ");
1256 xmlDebugErr2(ctxt
, XML_CHECK_ENTITY_TYPE
,
1257 "Unknown entity type %d\n", cur
->etype
);
1259 if (cur
->ExternalID
!= NULL
)
1260 fprintf(ctxt
->output
, "ID \"%s\"", (char *) cur
->ExternalID
);
1261 if (cur
->SystemID
!= NULL
)
1262 fprintf(ctxt
->output
, "SYSTEM \"%s\"", (char *) cur
->SystemID
);
1263 if (cur
->orig
!= NULL
)
1264 fprintf(ctxt
->output
, "\n orig \"%s\"", (char *) cur
->orig
);
1265 if ((cur
->type
!= XML_ELEMENT_NODE
) && (cur
->content
!= NULL
))
1266 fprintf(ctxt
->output
, "\n content \"%s\"",
1267 (char *) cur
->content
);
1268 fprintf(ctxt
->output
, "\n");
1273 * xmlCtxtDumpEntities:
1274 * @output: the FILE * for the output
1275 * @doc: the document
1277 * Dumps debug information for all the entities in use by the document
1280 xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt
, xmlDocPtr doc
)
1282 if (doc
== NULL
) return;
1283 xmlCtxtDumpDocHead(ctxt
, doc
);
1284 if ((doc
->intSubset
!= NULL
) && (doc
->intSubset
->entities
!= NULL
)) {
1285 xmlEntitiesTablePtr table
= (xmlEntitiesTablePtr
)
1286 doc
->intSubset
->entities
;
1289 fprintf(ctxt
->output
, "Entities in internal subset\n");
1290 xmlHashScan(table
, (xmlHashScanner
) xmlCtxtDumpEntityCallback
,
1293 fprintf(ctxt
->output
, "No entities in internal subset\n");
1294 if ((doc
->extSubset
!= NULL
) && (doc
->extSubset
->entities
!= NULL
)) {
1295 xmlEntitiesTablePtr table
= (xmlEntitiesTablePtr
)
1296 doc
->extSubset
->entities
;
1299 fprintf(ctxt
->output
, "Entities in external subset\n");
1300 xmlHashScan(table
, (xmlHashScanner
) xmlCtxtDumpEntityCallback
,
1302 } else if (!ctxt
->check
)
1303 fprintf(ctxt
->output
, "No entities in external subset\n");
1308 * @output: the FILE * for the output
1311 * Dumps debug information for the DTD
1314 xmlCtxtDumpDTD(xmlDebugCtxtPtr ctxt
, xmlDtdPtr dtd
)
1318 fprintf(ctxt
->output
, "DTD is NULL\n");
1321 xmlCtxtDumpDtdNode(ctxt
, dtd
);
1322 if (dtd
->children
== NULL
)
1323 fprintf(ctxt
->output
, " DTD is empty\n");
1326 xmlCtxtDumpNodeList(ctxt
, dtd
->children
);
1331 /************************************************************************
1333 * Public entry points for dump *
1335 ************************************************************************/
1338 * xmlDebugDumpString:
1339 * @output: the FILE * for the output
1342 * Dumps informations about the string, shorten it if necessary
1345 xmlDebugDumpString(FILE * output
, const xmlChar
* str
)
1352 fprintf(output
, "(NULL)");
1355 for (i
= 0; i
< 40; i
++)
1358 else if (IS_BLANK_CH(str
[i
]))
1360 else if (str
[i
] >= 0x80)
1361 fprintf(output
, "#%X", str
[i
]);
1363 fputc(str
[i
], output
);
1364 fprintf(output
, "...");
1369 * @output: the FILE * for the output
1370 * @attr: the attribute
1371 * @depth: the indentation level.
1373 * Dumps debug information for the attribute
1376 xmlDebugDumpAttr(FILE *output
, xmlAttrPtr attr
, int depth
) {
1379 if (output
== NULL
) return;
1380 xmlCtxtDumpInitCtxt(&ctxt
);
1381 ctxt
.output
= output
;
1383 xmlCtxtDumpAttr(&ctxt
, attr
);
1384 xmlCtxtDumpCleanCtxt(&ctxt
);
1389 * xmlDebugDumpEntities:
1390 * @output: the FILE * for the output
1391 * @doc: the document
1393 * Dumps debug information for all the entities in use by the document
1396 xmlDebugDumpEntities(FILE * output
, xmlDocPtr doc
)
1400 if (output
== NULL
) return;
1401 xmlCtxtDumpInitCtxt(&ctxt
);
1402 ctxt
.output
= output
;
1403 xmlCtxtDumpEntities(&ctxt
, doc
);
1404 xmlCtxtDumpCleanCtxt(&ctxt
);
1408 * xmlDebugDumpAttrList:
1409 * @output: the FILE * for the output
1410 * @attr: the attribute list
1411 * @depth: the indentation level.
1413 * Dumps debug information for the attribute list
1416 xmlDebugDumpAttrList(FILE * output
, xmlAttrPtr attr
, int depth
)
1420 if (output
== NULL
) return;
1421 xmlCtxtDumpInitCtxt(&ctxt
);
1422 ctxt
.output
= output
;
1424 xmlCtxtDumpAttrList(&ctxt
, attr
);
1425 xmlCtxtDumpCleanCtxt(&ctxt
);
1429 * xmlDebugDumpOneNode:
1430 * @output: the FILE * for the output
1432 * @depth: the indentation level.
1434 * Dumps debug information for the element node, it is not recursive
1437 xmlDebugDumpOneNode(FILE * output
, xmlNodePtr node
, int depth
)
1441 if (output
== NULL
) return;
1442 xmlCtxtDumpInitCtxt(&ctxt
);
1443 ctxt
.output
= output
;
1445 xmlCtxtDumpOneNode(&ctxt
, node
);
1446 xmlCtxtDumpCleanCtxt(&ctxt
);
1451 * @output: the FILE * for the output
1453 * @depth: the indentation level.
1455 * Dumps debug information for the element node, it is recursive
1458 xmlDebugDumpNode(FILE * output
, xmlNodePtr node
, int depth
)
1464 xmlCtxtDumpInitCtxt(&ctxt
);
1465 ctxt
.output
= output
;
1467 xmlCtxtDumpNode(&ctxt
, node
);
1468 xmlCtxtDumpCleanCtxt(&ctxt
);
1472 * xmlDebugDumpNodeList:
1473 * @output: the FILE * for the output
1474 * @node: the node list
1475 * @depth: the indentation level.
1477 * Dumps debug information for the list of element node, it is recursive
1480 xmlDebugDumpNodeList(FILE * output
, xmlNodePtr node
, int depth
)
1486 xmlCtxtDumpInitCtxt(&ctxt
);
1487 ctxt
.output
= output
;
1489 xmlCtxtDumpNodeList(&ctxt
, node
);
1490 xmlCtxtDumpCleanCtxt(&ctxt
);
1494 * xmlDebugDumpDocumentHead:
1495 * @output: the FILE * for the output
1496 * @doc: the document
1498 * Dumps debug information cncerning the document, not recursive
1501 xmlDebugDumpDocumentHead(FILE * output
, xmlDocPtr doc
)
1507 xmlCtxtDumpInitCtxt(&ctxt
);
1508 ctxt
.options
|= DUMP_TEXT_TYPE
;
1509 ctxt
.output
= output
;
1510 xmlCtxtDumpDocumentHead(&ctxt
, doc
);
1511 xmlCtxtDumpCleanCtxt(&ctxt
);
1515 * xmlDebugDumpDocument:
1516 * @output: the FILE * for the output
1517 * @doc: the document
1519 * Dumps debug information for the document, it's recursive
1522 xmlDebugDumpDocument(FILE * output
, xmlDocPtr doc
)
1528 xmlCtxtDumpInitCtxt(&ctxt
);
1529 ctxt
.options
|= DUMP_TEXT_TYPE
;
1530 ctxt
.output
= output
;
1531 xmlCtxtDumpDocument(&ctxt
, doc
);
1532 xmlCtxtDumpCleanCtxt(&ctxt
);
1537 * @output: the FILE * for the output
1540 * Dumps debug information for the DTD
1543 xmlDebugDumpDTD(FILE * output
, xmlDtdPtr dtd
)
1549 xmlCtxtDumpInitCtxt(&ctxt
);
1550 ctxt
.options
|= DUMP_TEXT_TYPE
;
1551 ctxt
.output
= output
;
1552 xmlCtxtDumpDTD(&ctxt
, dtd
);
1553 xmlCtxtDumpCleanCtxt(&ctxt
);
1556 /************************************************************************
1558 * Public entry points for checkings *
1560 ************************************************************************/
1563 * xmlDebugCheckDocument:
1564 * @output: the FILE * for the output
1565 * @doc: the document
1567 * Check the document for potential content problems, and output
1568 * the errors to @output
1570 * Returns the number of errors found
1573 xmlDebugCheckDocument(FILE * output
, xmlDocPtr doc
)
1579 xmlCtxtDumpInitCtxt(&ctxt
);
1580 ctxt
.output
= output
;
1582 xmlCtxtDumpDocument(&ctxt
, doc
);
1583 xmlCtxtDumpCleanCtxt(&ctxt
);
1584 return(ctxt
.errors
);
1587 /************************************************************************
1589 * Helpers for Shell *
1591 ************************************************************************/
1595 * @node: the node to count
1597 * Count the children of @node.
1599 * Returns the number of children of @node.
1602 xmlLsCountNode(xmlNodePtr node
) {
1604 xmlNodePtr list
= NULL
;
1609 switch (node
->type
) {
1610 case XML_ELEMENT_NODE
:
1611 list
= node
->children
;
1613 case XML_DOCUMENT_NODE
:
1614 case XML_HTML_DOCUMENT_NODE
:
1615 #ifdef LIBXML_DOCB_ENABLED
1616 case XML_DOCB_DOCUMENT_NODE
:
1618 list
= ((xmlDocPtr
) node
)->children
;
1620 case XML_ATTRIBUTE_NODE
:
1621 list
= ((xmlAttrPtr
) node
)->children
;
1624 case XML_CDATA_SECTION_NODE
:
1626 case XML_COMMENT_NODE
:
1627 if (node
->content
!= NULL
) {
1628 ret
= xmlStrlen(node
->content
);
1631 case XML_ENTITY_REF_NODE
:
1632 case XML_DOCUMENT_TYPE_NODE
:
1633 case XML_ENTITY_NODE
:
1634 case XML_DOCUMENT_FRAG_NODE
:
1635 case XML_NOTATION_NODE
:
1637 case XML_ELEMENT_DECL
:
1638 case XML_ATTRIBUTE_DECL
:
1639 case XML_ENTITY_DECL
:
1640 case XML_NAMESPACE_DECL
:
1641 case XML_XINCLUDE_START
:
1642 case XML_XINCLUDE_END
:
1646 for (;list
!= NULL
;ret
++)
1653 * @output: the FILE * for the output
1654 * @node: the node to dump
1656 * Dump to @output the type and name of @node.
1659 xmlLsOneNode(FILE *output
, xmlNodePtr node
) {
1660 if (output
== NULL
) return;
1662 fprintf(output
, "NULL\n");
1665 switch (node
->type
) {
1666 case XML_ELEMENT_NODE
:
1667 fprintf(output
, "-");
1669 case XML_ATTRIBUTE_NODE
:
1670 fprintf(output
, "a");
1673 fprintf(output
, "t");
1675 case XML_CDATA_SECTION_NODE
:
1676 fprintf(output
, "C");
1678 case XML_ENTITY_REF_NODE
:
1679 fprintf(output
, "e");
1681 case XML_ENTITY_NODE
:
1682 fprintf(output
, "E");
1685 fprintf(output
, "p");
1687 case XML_COMMENT_NODE
:
1688 fprintf(output
, "c");
1690 case XML_DOCUMENT_NODE
:
1691 fprintf(output
, "d");
1693 case XML_HTML_DOCUMENT_NODE
:
1694 fprintf(output
, "h");
1696 case XML_DOCUMENT_TYPE_NODE
:
1697 fprintf(output
, "T");
1699 case XML_DOCUMENT_FRAG_NODE
:
1700 fprintf(output
, "F");
1702 case XML_NOTATION_NODE
:
1703 fprintf(output
, "N");
1705 case XML_NAMESPACE_DECL
:
1706 fprintf(output
, "n");
1709 fprintf(output
, "?");
1711 if (node
->type
!= XML_NAMESPACE_DECL
) {
1712 if (node
->properties
!= NULL
)
1713 fprintf(output
, "a");
1715 fprintf(output
, "-");
1716 if (node
->nsDef
!= NULL
)
1717 fprintf(output
, "n");
1719 fprintf(output
, "-");
1722 fprintf(output
, " %8d ", xmlLsCountNode(node
));
1724 switch (node
->type
) {
1725 case XML_ELEMENT_NODE
:
1726 if (node
->name
!= NULL
)
1727 fprintf(output
, "%s", (const char *) node
->name
);
1729 case XML_ATTRIBUTE_NODE
:
1730 if (node
->name
!= NULL
)
1731 fprintf(output
, "%s", (const char *) node
->name
);
1734 if (node
->content
!= NULL
) {
1735 xmlDebugDumpString(output
, node
->content
);
1738 case XML_CDATA_SECTION_NODE
:
1740 case XML_ENTITY_REF_NODE
:
1741 if (node
->name
!= NULL
)
1742 fprintf(output
, "%s", (const char *) node
->name
);
1744 case XML_ENTITY_NODE
:
1745 if (node
->name
!= NULL
)
1746 fprintf(output
, "%s", (const char *) node
->name
);
1749 if (node
->name
!= NULL
)
1750 fprintf(output
, "%s", (const char *) node
->name
);
1752 case XML_COMMENT_NODE
:
1754 case XML_DOCUMENT_NODE
:
1756 case XML_HTML_DOCUMENT_NODE
:
1758 case XML_DOCUMENT_TYPE_NODE
:
1760 case XML_DOCUMENT_FRAG_NODE
:
1762 case XML_NOTATION_NODE
:
1764 case XML_NAMESPACE_DECL
: {
1765 xmlNsPtr ns
= (xmlNsPtr
) node
;
1767 if (ns
->prefix
== NULL
)
1768 fprintf(output
, "default -> %s", (char *)ns
->href
);
1770 fprintf(output
, "%s -> %s", (char *)ns
->prefix
,
1775 if (node
->name
!= NULL
)
1776 fprintf(output
, "%s", (const char *) node
->name
);
1778 fprintf(output
, "\n");
1783 * @boolval: a bool to turn into text
1785 * Convenient way to turn bool into text
1787 * Returns a pointer to either "True" or "False"
1790 xmlBoolToText(int boolval
)
1798 #ifdef LIBXML_XPATH_ENABLED
1799 /****************************************************************
1801 * The XML shell related functions *
1803 ****************************************************************/
1808 * TODO: Improvement/cleanups for the XML shell
1809 * - allow to shell out an editor on a subpart
1810 * - cleanup function registrations (with help) and calling
1811 * - provide registration routines
1815 * xmlShellPrintXPathError:
1816 * @errorType: valid xpath error id
1817 * @arg: the argument that cause xpath to fail
1819 * Print the xpath error to libxml default error channel
1822 xmlShellPrintXPathError(int errorType
, const char *arg
)
1824 const char *default_arg
= "Result";
1829 switch (errorType
) {
1830 case XPATH_UNDEFINED
:
1831 xmlGenericError(xmlGenericErrorContext
,
1832 "%s: no such node\n", arg
);
1836 xmlGenericError(xmlGenericErrorContext
,
1837 "%s is a Boolean\n", arg
);
1840 xmlGenericError(xmlGenericErrorContext
,
1841 "%s is a number\n", arg
);
1844 xmlGenericError(xmlGenericErrorContext
,
1845 "%s is a string\n", arg
);
1848 xmlGenericError(xmlGenericErrorContext
,
1849 "%s is a point\n", arg
);
1852 xmlGenericError(xmlGenericErrorContext
,
1853 "%s is a range\n", arg
);
1855 case XPATH_LOCATIONSET
:
1856 xmlGenericError(xmlGenericErrorContext
,
1857 "%s is a range\n", arg
);
1860 xmlGenericError(xmlGenericErrorContext
,
1861 "%s is user-defined\n", arg
);
1863 case XPATH_XSLT_TREE
:
1864 xmlGenericError(xmlGenericErrorContext
,
1865 "%s is an XSLT value tree\n", arg
);
1869 xmlGenericError(xmlGenericErrorContext
,
1870 "Try casting the result string function (xpath builtin)\n",
1876 #ifdef LIBXML_OUTPUT_ENABLED
1878 * xmlShellPrintNodeCtxt:
1879 * @ctxt : a non-null shell context
1880 * @node : a non-null node to print to the output FILE
1882 * Print node to the output FILE
1885 xmlShellPrintNodeCtxt(xmlShellCtxtPtr ctxt
,xmlNodePtr node
)
1896 if (node
->type
== XML_DOCUMENT_NODE
)
1897 xmlDocDump(fp
, (xmlDocPtr
) node
);
1898 else if (node
->type
== XML_ATTRIBUTE_NODE
)
1899 xmlDebugDumpAttrList(fp
, (xmlAttrPtr
) node
, 0);
1901 xmlElemDump(fp
, node
->doc
, node
);
1907 * xmlShellPrintNode:
1908 * @node : a non-null node to print to the output FILE
1910 * Print node to the output FILE
1913 xmlShellPrintNode(xmlNodePtr node
)
1915 xmlShellPrintNodeCtxt(NULL
, node
);
1917 #endif /* LIBXML_OUTPUT_ENABLED */
1920 * xmlShellPrintXPathResultCtxt:
1921 * @ctxt: a valid shell context
1922 * @list: a valid result generated by an xpath evaluation
1924 * Prints result to the output FILE
1927 xmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt
,xmlXPathObjectPtr list
)
1933 switch (list
->type
) {
1934 case XPATH_NODESET
:{
1935 #ifdef LIBXML_OUTPUT_ENABLED
1938 if (list
->nodesetval
) {
1939 for (indx
= 0; indx
< list
->nodesetval
->nodeNr
;
1941 xmlShellPrintNodeCtxt(ctxt
,
1942 list
->nodesetval
->nodeTab
[indx
]);
1945 xmlGenericError(xmlGenericErrorContext
,
1946 "Empty node set\n");
1950 xmlGenericError(xmlGenericErrorContext
,
1952 #endif /* LIBXML_OUTPUT_ENABLED */
1955 xmlGenericError(xmlGenericErrorContext
,
1956 "Is a Boolean:%s\n",
1957 xmlBoolToText(list
->boolval
));
1960 xmlGenericError(xmlGenericErrorContext
,
1961 "Is a number:%0g\n", list
->floatval
);
1964 xmlGenericError(xmlGenericErrorContext
,
1965 "Is a string:%s\n", list
->stringval
);
1969 xmlShellPrintXPathError(list
->type
, NULL
);
1975 * xmlShellPrintXPathResult:
1976 * @list: a valid result generated by an xpath evaluation
1978 * Prints result to the output FILE
1981 xmlShellPrintXPathResult(xmlXPathObjectPtr list
)
1983 xmlShellPrintXPathResultCtxt(NULL
, list
);
1988 * @ctxt: the shell context
1993 * Implements the XML shell function "ls"
1994 * Does an Unix like listing of the given node (like a directory)
1999 xmlShellList(xmlShellCtxtPtr ctxt
,
2000 char *arg ATTRIBUTE_UNUSED
, xmlNodePtr node
,
2001 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2007 fprintf(ctxt
->output
, "NULL\n");
2010 if ((node
->type
== XML_DOCUMENT_NODE
) ||
2011 (node
->type
== XML_HTML_DOCUMENT_NODE
)) {
2012 cur
= ((xmlDocPtr
) node
)->children
;
2013 } else if (node
->type
== XML_NAMESPACE_DECL
) {
2014 xmlLsOneNode(ctxt
->output
, node
);
2016 } else if (node
->children
!= NULL
) {
2017 cur
= node
->children
;
2019 xmlLsOneNode(ctxt
->output
, node
);
2022 while (cur
!= NULL
) {
2023 xmlLsOneNode(ctxt
->output
, cur
);
2031 * @ctxt: the shell context
2036 * Implements the XML shell function "base"
2037 * dumps the current XML base of the node
2042 xmlShellBase(xmlShellCtxtPtr ctxt
,
2043 char *arg ATTRIBUTE_UNUSED
, xmlNodePtr node
,
2044 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2050 fprintf(ctxt
->output
, "NULL\n");
2054 base
= xmlNodeGetBase(node
->doc
, node
);
2057 fprintf(ctxt
->output
, " No base found !!!\n");
2059 fprintf(ctxt
->output
, "%s\n", base
);
2065 #ifdef LIBXML_TREE_ENABLED
2068 * @ctxt: the shell context
2069 * @arg: the new base
2073 * Implements the XML shell function "setbase"
2074 * change the current XML base of the node
2079 xmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED
,
2080 char *arg ATTRIBUTE_UNUSED
, xmlNodePtr node
,
2081 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2083 xmlNodeSetBase(node
, (xmlChar
*) arg
);
2088 #ifdef LIBXML_XPATH_ENABLED
2090 * xmlShellRegisterNamespace:
2091 * @ctxt: the shell context
2092 * @arg: a string in prefix=nsuri format
2096 * Implements the XML shell function "setns"
2097 * register/unregister a prefix=namespace pair
2098 * on the XPath context
2100 * Returns 0 on success and a negative value otherwise.
2103 xmlShellRegisterNamespace(xmlShellCtxtPtr ctxt
, char *arg
,
2104 xmlNodePtr node ATTRIBUTE_UNUSED
, xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2111 nsListDup
= xmlStrdup((xmlChar
*) arg
);
2113 while(next
!= NULL
) {
2115 /*while((*next) == ' ') next++;*/
2116 if((*next
) == '\0') break;
2120 next
= (xmlChar
*)xmlStrchr(next
, '=');
2122 fprintf(ctxt
->output
, "setns: prefix=[nsuri] required\n");
2130 next
= (xmlChar
*)xmlStrchr(next
, ' ');
2135 /* do register namespace */
2136 if(xmlXPathRegisterNs(ctxt
->pctxt
, prefix
, href
) != 0) {
2137 fprintf(ctxt
->output
,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix
, href
);
2147 * xmlShellRegisterRootNamespaces:
2148 * @ctxt: the shell context
2150 * @node: the root element
2153 * Implements the XML shell function "setrootns"
2154 * which registers all namespaces declarations found on the root element.
2156 * Returns 0 on success and a negative value otherwise.
2159 xmlShellRegisterRootNamespaces(xmlShellCtxtPtr ctxt
, char *arg ATTRIBUTE_UNUSED
,
2160 xmlNodePtr root
, xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2164 if ((root
== NULL
) || (root
->type
!= XML_ELEMENT_NODE
) ||
2165 (root
->nsDef
== NULL
) || (ctxt
== NULL
) || (ctxt
->pctxt
== NULL
))
2168 while (ns
!= NULL
) {
2169 if (ns
->prefix
== NULL
)
2170 xmlXPathRegisterNs(ctxt
->pctxt
, BAD_CAST
"defaultns", ns
->href
);
2172 xmlXPathRegisterNs(ctxt
->pctxt
, ns
->prefix
, ns
->href
);
2181 * @ctxt: the shell context
2182 * @arg: the string or regular expression to find
2186 * Implements the XML shell function "grep"
2187 * dumps informations about the node (namespace, attributes, content).
2192 xmlShellGrep(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED
,
2193 char *arg
, xmlNodePtr node
, xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2201 #ifdef LIBXML_REGEXP_ENABLED
2202 if ((xmlStrchr((xmlChar
*) arg
, '?')) ||
2203 (xmlStrchr((xmlChar
*) arg
, '*')) ||
2204 (xmlStrchr((xmlChar
*) arg
, '.')) ||
2205 (xmlStrchr((xmlChar
*) arg
, '['))) {
2208 while (node
!= NULL
) {
2209 if (node
->type
== XML_COMMENT_NODE
) {
2210 if (xmlStrstr(node
->content
, (xmlChar
*) arg
)) {
2212 fprintf(ctxt
->output
, "%s : ", xmlGetNodePath(node
));
2213 xmlShellList(ctxt
, NULL
, node
, NULL
);
2215 } else if (node
->type
== XML_TEXT_NODE
) {
2216 if (xmlStrstr(node
->content
, (xmlChar
*) arg
)) {
2218 fprintf(ctxt
->output
, "%s : ", xmlGetNodePath(node
->parent
));
2219 xmlShellList(ctxt
, NULL
, node
->parent
, NULL
);
2224 * Browse the full subtree, deep first
2227 if ((node
->type
== XML_DOCUMENT_NODE
) ||
2228 (node
->type
== XML_HTML_DOCUMENT_NODE
)) {
2229 node
= ((xmlDocPtr
) node
)->children
;
2230 } else if ((node
->children
!= NULL
)
2231 && (node
->type
!= XML_ENTITY_REF_NODE
)) {
2233 node
= node
->children
;
2234 } else if (node
->next
!= NULL
) {
2238 /* go up to parents->next if needed */
2239 while (node
!= NULL
) {
2240 if (node
->parent
!= NULL
) {
2241 node
= node
->parent
;
2243 if (node
->next
!= NULL
) {
2247 if (node
->parent
== NULL
) {
2259 * @ctxt: the shell context
2264 * Implements the XML shell function "dir"
2265 * dumps informations about the node (namespace, attributes, content).
2270 xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED
,
2271 char *arg ATTRIBUTE_UNUSED
, xmlNodePtr node
,
2272 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2277 fprintf(ctxt
->output
, "NULL\n");
2280 if ((node
->type
== XML_DOCUMENT_NODE
) ||
2281 (node
->type
== XML_HTML_DOCUMENT_NODE
)) {
2282 xmlDebugDumpDocumentHead(ctxt
->output
, (xmlDocPtr
) node
);
2283 } else if (node
->type
== XML_ATTRIBUTE_NODE
) {
2284 xmlDebugDumpAttr(ctxt
->output
, (xmlAttrPtr
) node
, 0);
2286 xmlDebugDumpOneNode(ctxt
->output
, node
, 0);
2292 * xmlShellSetContent:
2293 * @ctxt: the shell context
2294 * @value: the content as a string
2298 * Implements the XML shell function "dir"
2299 * dumps informations about the node (namespace, attributes, content).
2304 xmlShellSetContent(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED
,
2305 char *value
, xmlNodePtr node
,
2306 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2309 xmlParserErrors ret
;
2314 fprintf(ctxt
->output
, "NULL\n");
2317 if (value
== NULL
) {
2318 fprintf(ctxt
->output
, "NULL\n");
2322 ret
= xmlParseInNodeContext(node
, value
, strlen(value
), 0, &results
);
2323 if (ret
== XML_ERR_OK
) {
2324 if (node
->children
!= NULL
) {
2325 xmlFreeNodeList(node
->children
);
2326 node
->children
= NULL
;
2329 xmlAddChildList(node
, results
);
2331 fprintf(ctxt
->output
, "failed to parse content\n");
2336 #ifdef LIBXML_SCHEMAS_ENABLED
2338 * xmlShellRNGValidate:
2339 * @ctxt: the shell context
2340 * @schemas: the path to the Relax-NG schemas
2344 * Implements the XML shell function "relaxng"
2345 * validating the instance against a Relax-NG schemas
2350 xmlShellRNGValidate(xmlShellCtxtPtr sctxt
, char *schemas
,
2351 xmlNodePtr node ATTRIBUTE_UNUSED
,
2352 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2354 xmlRelaxNGPtr relaxngschemas
;
2355 xmlRelaxNGParserCtxtPtr ctxt
;
2356 xmlRelaxNGValidCtxtPtr vctxt
;
2359 ctxt
= xmlRelaxNGNewParserCtxt(schemas
);
2360 xmlRelaxNGSetParserErrors(ctxt
,
2361 (xmlRelaxNGValidityErrorFunc
) fprintf
,
2362 (xmlRelaxNGValidityWarningFunc
) fprintf
,
2364 relaxngschemas
= xmlRelaxNGParse(ctxt
);
2365 xmlRelaxNGFreeParserCtxt(ctxt
);
2366 if (relaxngschemas
== NULL
) {
2367 xmlGenericError(xmlGenericErrorContext
,
2368 "Relax-NG schema %s failed to compile\n", schemas
);
2371 vctxt
= xmlRelaxNGNewValidCtxt(relaxngschemas
);
2372 xmlRelaxNGSetValidErrors(vctxt
,
2373 (xmlRelaxNGValidityErrorFunc
) fprintf
,
2374 (xmlRelaxNGValidityWarningFunc
) fprintf
,
2376 ret
= xmlRelaxNGValidateDoc(vctxt
, sctxt
->doc
);
2378 fprintf(stderr
, "%s validates\n", sctxt
->filename
);
2379 } else if (ret
> 0) {
2380 fprintf(stderr
, "%s fails to validate\n", sctxt
->filename
);
2382 fprintf(stderr
, "%s validation generated an internal error\n",
2385 xmlRelaxNGFreeValidCtxt(vctxt
);
2386 if (relaxngschemas
!= NULL
)
2387 xmlRelaxNGFree(relaxngschemas
);
2392 #ifdef LIBXML_OUTPUT_ENABLED
2395 * @ctxt: the shell context
2400 * Implements the XML shell function "cat"
2401 * dumps the serialization node content (XML or HTML).
2406 xmlShellCat(xmlShellCtxtPtr ctxt
, char *arg ATTRIBUTE_UNUSED
,
2407 xmlNodePtr node
, xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2412 fprintf(ctxt
->output
, "NULL\n");
2415 if (ctxt
->doc
->type
== XML_HTML_DOCUMENT_NODE
) {
2416 #ifdef LIBXML_HTML_ENABLED
2417 if (node
->type
== XML_HTML_DOCUMENT_NODE
)
2418 htmlDocDump(ctxt
->output
, (htmlDocPtr
) node
);
2420 htmlNodeDumpFile(ctxt
->output
, ctxt
->doc
, node
);
2422 if (node
->type
== XML_DOCUMENT_NODE
)
2423 xmlDocDump(ctxt
->output
, (xmlDocPtr
) node
);
2425 xmlElemDump(ctxt
->output
, ctxt
->doc
, node
);
2426 #endif /* LIBXML_HTML_ENABLED */
2428 if (node
->type
== XML_DOCUMENT_NODE
)
2429 xmlDocDump(ctxt
->output
, (xmlDocPtr
) node
);
2431 xmlElemDump(ctxt
->output
, ctxt
->doc
, node
);
2433 fprintf(ctxt
->output
, "\n");
2436 #endif /* LIBXML_OUTPUT_ENABLED */
2440 * @ctxt: the shell context
2441 * @filename: the file name
2445 * Implements the XML shell function "load"
2446 * loads a new document specified by the filename
2448 * Returns 0 or -1 if loading failed
2451 xmlShellLoad(xmlShellCtxtPtr ctxt
, char *filename
,
2452 xmlNodePtr node ATTRIBUTE_UNUSED
,
2453 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2458 if ((ctxt
== NULL
) || (filename
== NULL
)) return(-1);
2459 if (ctxt
->doc
!= NULL
)
2460 html
= (ctxt
->doc
->type
== XML_HTML_DOCUMENT_NODE
);
2463 #ifdef LIBXML_HTML_ENABLED
2464 doc
= htmlParseFile(filename
, NULL
);
2466 fprintf(ctxt
->output
, "HTML support not compiled in\n");
2468 #endif /* LIBXML_HTML_ENABLED */
2470 doc
= xmlReadFile(filename
,NULL
,0);
2473 if (ctxt
->loaded
== 1) {
2474 xmlFreeDoc(ctxt
->doc
);
2477 #ifdef LIBXML_XPATH_ENABLED
2478 xmlXPathFreeContext(ctxt
->pctxt
);
2479 #endif /* LIBXML_XPATH_ENABLED */
2480 xmlFree(ctxt
->filename
);
2482 ctxt
->node
= (xmlNodePtr
) doc
;
2483 #ifdef LIBXML_XPATH_ENABLED
2484 ctxt
->pctxt
= xmlXPathNewContext(doc
);
2485 #endif /* LIBXML_XPATH_ENABLED */
2486 ctxt
->filename
= (char *) xmlCanonicPath((xmlChar
*) filename
);
2492 #ifdef LIBXML_OUTPUT_ENABLED
2495 * @ctxt: the shell context
2496 * @filename: the file name
2497 * @node: a node in the tree
2500 * Implements the XML shell function "write"
2501 * Write the current node to the filename, it saves the serialization
2502 * of the subtree under the @node specified
2504 * Returns 0 or -1 in case of error
2507 xmlShellWrite(xmlShellCtxtPtr ctxt
, char *filename
, xmlNodePtr node
,
2508 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2512 if ((filename
== NULL
) || (filename
[0] == 0)) {
2516 if (access((char *) filename
, W_OK
)) {
2517 xmlGenericError(xmlGenericErrorContext
,
2518 "Cannot write to %s\n", filename
);
2522 switch (node
->type
) {
2523 case XML_DOCUMENT_NODE
:
2524 if (xmlSaveFile((char *) filename
, ctxt
->doc
) < -1) {
2525 xmlGenericError(xmlGenericErrorContext
,
2526 "Failed to write to %s\n", filename
);
2530 case XML_HTML_DOCUMENT_NODE
:
2531 #ifdef LIBXML_HTML_ENABLED
2532 if (htmlSaveFile((char *) filename
, ctxt
->doc
) < 0) {
2533 xmlGenericError(xmlGenericErrorContext
,
2534 "Failed to write to %s\n", filename
);
2538 if (xmlSaveFile((char *) filename
, ctxt
->doc
) < -1) {
2539 xmlGenericError(xmlGenericErrorContext
,
2540 "Failed to write to %s\n", filename
);
2543 #endif /* LIBXML_HTML_ENABLED */
2548 f
= fopen((char *) filename
, "w");
2550 xmlGenericError(xmlGenericErrorContext
,
2551 "Failed to write to %s\n", filename
);
2554 xmlElemDump(f
, ctxt
->doc
, node
);
2563 * @ctxt: the shell context
2564 * @filename: the file name (optional)
2568 * Implements the XML shell function "save"
2569 * Write the current document to the filename, or it's original name
2571 * Returns 0 or -1 in case of error
2574 xmlShellSave(xmlShellCtxtPtr ctxt
, char *filename
,
2575 xmlNodePtr node ATTRIBUTE_UNUSED
,
2576 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2578 if ((ctxt
== NULL
) || (ctxt
->doc
== NULL
))
2580 if ((filename
== NULL
) || (filename
[0] == 0))
2581 filename
= ctxt
->filename
;
2582 if (filename
== NULL
)
2585 if (access((char *) filename
, W_OK
)) {
2586 xmlGenericError(xmlGenericErrorContext
,
2587 "Cannot save to %s\n", filename
);
2591 switch (ctxt
->doc
->type
) {
2592 case XML_DOCUMENT_NODE
:
2593 if (xmlSaveFile((char *) filename
, ctxt
->doc
) < 0) {
2594 xmlGenericError(xmlGenericErrorContext
,
2595 "Failed to save to %s\n", filename
);
2598 case XML_HTML_DOCUMENT_NODE
:
2599 #ifdef LIBXML_HTML_ENABLED
2600 if (htmlSaveFile((char *) filename
, ctxt
->doc
) < 0) {
2601 xmlGenericError(xmlGenericErrorContext
,
2602 "Failed to save to %s\n", filename
);
2605 if (xmlSaveFile((char *) filename
, ctxt
->doc
) < 0) {
2606 xmlGenericError(xmlGenericErrorContext
,
2607 "Failed to save to %s\n", filename
);
2609 #endif /* LIBXML_HTML_ENABLED */
2612 xmlGenericError(xmlGenericErrorContext
,
2613 "To save to subparts of a document use the 'write' command\n");
2619 #endif /* LIBXML_OUTPUT_ENABLED */
2621 #ifdef LIBXML_VALID_ENABLED
2624 * @ctxt: the shell context
2625 * @dtd: the DTD URI (optional)
2629 * Implements the XML shell function "validate"
2630 * Validate the document, if a DTD path is provided, then the validation
2631 * is done against the given DTD.
2633 * Returns 0 or -1 in case of error
2636 xmlShellValidate(xmlShellCtxtPtr ctxt
, char *dtd
,
2637 xmlNodePtr node ATTRIBUTE_UNUSED
,
2638 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2643 if ((ctxt
== NULL
) || (ctxt
->doc
== NULL
)) return(-1);
2644 vctxt
.userData
= stderr
;
2645 vctxt
.error
= (xmlValidityErrorFunc
) fprintf
;
2646 vctxt
.warning
= (xmlValidityWarningFunc
) fprintf
;
2648 if ((dtd
== NULL
) || (dtd
[0] == 0)) {
2649 res
= xmlValidateDocument(&vctxt
, ctxt
->doc
);
2653 subset
= xmlParseDTD(NULL
, (xmlChar
*) dtd
);
2654 if (subset
!= NULL
) {
2655 res
= xmlValidateDtd(&vctxt
, ctxt
->doc
, subset
);
2662 #endif /* LIBXML_VALID_ENABLED */
2666 * @ctxt: the shell context
2668 * @tree: a node defining a subtree
2671 * Implements the XML shell function "du"
2672 * show the structure of the subtree under node @tree
2673 * If @tree is null, the command works on the current node.
2675 * Returns 0 or -1 in case of error
2678 xmlShellDu(xmlShellCtxtPtr ctxt
,
2679 char *arg ATTRIBUTE_UNUSED
, xmlNodePtr tree
,
2680 xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2691 while (node
!= NULL
) {
2692 if ((node
->type
== XML_DOCUMENT_NODE
) ||
2693 (node
->type
== XML_HTML_DOCUMENT_NODE
)) {
2694 fprintf(ctxt
->output
, "/\n");
2695 } else if (node
->type
== XML_ELEMENT_NODE
) {
2696 for (i
= 0; i
< indent
; i
++)
2697 fprintf(ctxt
->output
, " ");
2698 fprintf(ctxt
->output
, "%s\n", node
->name
);
2703 * Browse the full subtree, deep first
2706 if ((node
->type
== XML_DOCUMENT_NODE
) ||
2707 (node
->type
== XML_HTML_DOCUMENT_NODE
)) {
2708 node
= ((xmlDocPtr
) node
)->children
;
2709 } else if ((node
->children
!= NULL
)
2710 && (node
->type
!= XML_ENTITY_REF_NODE
)) {
2712 node
= node
->children
;
2714 } else if ((node
!= tree
) && (node
->next
!= NULL
)) {
2717 } else if (node
!= tree
) {
2718 /* go up to parents->next if needed */
2719 while (node
!= tree
) {
2720 if (node
->parent
!= NULL
) {
2721 node
= node
->parent
;
2724 if ((node
!= tree
) && (node
->next
!= NULL
)) {
2728 if (node
->parent
== NULL
) {
2737 /* exit condition */
2748 * @ctxt: the shell context
2749 * @buffer: the output buffer
2753 * Implements the XML shell function "pwd"
2754 * Show the full path from the root to the node, if needed building
2755 * thumblers when similar elements exists at a given ancestor level.
2756 * The output is compatible with XPath commands.
2758 * Returns 0 or -1 in case of error
2761 xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED
, char *buffer
,
2762 xmlNodePtr node
, xmlNodePtr node2 ATTRIBUTE_UNUSED
)
2766 if ((node
== NULL
) || (buffer
== NULL
))
2769 path
= xmlGetNodePath(node
);
2774 * This test prevents buffer overflow, because this routine
2775 * is only called by xmlShell, in which the second argument is
2777 * It is a dirty hack before a cleaner solution is found.
2778 * Documentation should mention that the second argument must
2779 * be at least 500 chars long, and could be stripped if too long.
2781 snprintf(buffer
, 499, "%s", path
);
2790 * @doc: the initial document
2791 * @filename: the output buffer
2792 * @input: the line reading function
2793 * @output: the output FILE*, defaults to stdout if NULL
2795 * Implements the XML shell
2796 * This allow to load, validate, view, modify and save a document
2797 * using a environment similar to a UNIX commandline.
2800 xmlShell(xmlDocPtr doc
, char *filename
, xmlShellReadlineFunc input
,
2803 char prompt
[500] = "/ > ";
2804 char *cmdline
= NULL
, *cur
;
2808 xmlShellCtxtPtr ctxt
;
2809 xmlXPathObjectPtr list
;
2813 if (filename
== NULL
)
2819 ctxt
= (xmlShellCtxtPtr
) xmlMalloc(sizeof(xmlShellCtxt
));
2824 ctxt
->input
= input
;
2825 ctxt
->output
= output
;
2826 ctxt
->filename
= (char *) xmlStrdup((xmlChar
*) filename
);
2827 ctxt
->node
= (xmlNodePtr
) ctxt
->doc
;
2829 #ifdef LIBXML_XPATH_ENABLED
2830 ctxt
->pctxt
= xmlXPathNewContext(ctxt
->doc
);
2831 if (ctxt
->pctxt
== NULL
) {
2835 #endif /* LIBXML_XPATH_ENABLED */
2837 if (ctxt
->node
== (xmlNodePtr
) ctxt
->doc
)
2838 snprintf(prompt
, sizeof(prompt
), "%s > ", "/");
2839 else if ((ctxt
->node
!= NULL
) && (ctxt
->node
->name
))
2840 snprintf(prompt
, sizeof(prompt
), "%s > ", ctxt
->node
->name
);
2842 snprintf(prompt
, sizeof(prompt
), "? > ");
2843 prompt
[sizeof(prompt
) - 1] = 0;
2846 * Get a new command line
2848 cmdline
= ctxt
->input(prompt
);
2849 if (cmdline
== NULL
)
2853 * Parse the command itself
2856 while ((*cur
== ' ') || (*cur
== '\t'))
2859 while ((*cur
!= ' ') && (*cur
!= '\t') &&
2860 (*cur
!= '\n') && (*cur
!= '\r')) {
2863 command
[i
++] = *cur
++;
2870 * Parse the argument
2872 while ((*cur
== ' ') || (*cur
== '\t'))
2875 while ((*cur
!= '\n') && (*cur
!= '\r') && (*cur
!= 0)) {
2883 * start interpreting the command
2885 if (!strcmp(command
, "exit"))
2887 if (!strcmp(command
, "quit"))
2889 if (!strcmp(command
, "bye"))
2891 if (!strcmp(command
, "help")) {
2892 fprintf(ctxt
->output
, "\tbase display XML base of the node\n");
2893 fprintf(ctxt
->output
, "\tsetbase URI change the XML base of the node\n");
2894 fprintf(ctxt
->output
, "\tbye leave shell\n");
2895 fprintf(ctxt
->output
, "\tcat [node] display node or current node\n");
2896 fprintf(ctxt
->output
, "\tcd [path] change directory to path or to root\n");
2897 fprintf(ctxt
->output
, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n");
2898 fprintf(ctxt
->output
, "\tdu [path] show the structure of the subtree under path or the current node\n");
2899 fprintf(ctxt
->output
, "\texit leave shell\n");
2900 fprintf(ctxt
->output
, "\thelp display this help\n");
2901 fprintf(ctxt
->output
, "\tfree display memory usage\n");
2902 fprintf(ctxt
->output
, "\tload [name] load a new document with name\n");
2903 fprintf(ctxt
->output
, "\tls [path] list contents of path or the current directory\n");
2904 fprintf(ctxt
->output
, "\tset xml_fragment replace the current node content with the fragment parsed in context\n");
2905 #ifdef LIBXML_XPATH_ENABLED
2906 fprintf(ctxt
->output
, "\txpath expr evaluate the XPath expression in that context and print the result\n");
2907 fprintf(ctxt
->output
, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n");
2908 fprintf(ctxt
->output
, "\t format for nsreg is: prefix=[nsuri] (i.e. prefix= unsets a prefix)\n");
2909 fprintf(ctxt
->output
, "\tsetrootns register all namespace found on the root element\n");
2910 fprintf(ctxt
->output
, "\t the default namespace if any uses 'defaultns' prefix\n");
2911 #endif /* LIBXML_XPATH_ENABLED */
2912 fprintf(ctxt
->output
, "\tpwd display current working directory\n");
2913 fprintf(ctxt
->output
, "\tquit leave shell\n");
2914 #ifdef LIBXML_OUTPUT_ENABLED
2915 fprintf(ctxt
->output
, "\tsave [name] save this document to name or the original name\n");
2916 fprintf(ctxt
->output
, "\twrite [name] write the current node to the filename\n");
2917 #endif /* LIBXML_OUTPUT_ENABLED */
2918 #ifdef LIBXML_VALID_ENABLED
2919 fprintf(ctxt
->output
, "\tvalidate check the document for errors\n");
2920 #endif /* LIBXML_VALID_ENABLED */
2921 #ifdef LIBXML_SCHEMAS_ENABLED
2922 fprintf(ctxt
->output
, "\trelaxng rng validate the document agaisnt the Relax-NG schemas\n");
2924 fprintf(ctxt
->output
, "\tgrep string search for a string in the subtree\n");
2925 #ifdef LIBXML_VALID_ENABLED
2926 } else if (!strcmp(command
, "validate")) {
2927 xmlShellValidate(ctxt
, arg
, NULL
, NULL
);
2928 #endif /* LIBXML_VALID_ENABLED */
2929 } else if (!strcmp(command
, "load")) {
2930 xmlShellLoad(ctxt
, arg
, NULL
, NULL
);
2931 #ifdef LIBXML_SCHEMAS_ENABLED
2932 } else if (!strcmp(command
, "relaxng")) {
2933 xmlShellRNGValidate(ctxt
, arg
, NULL
, NULL
);
2935 #ifdef LIBXML_OUTPUT_ENABLED
2936 } else if (!strcmp(command
, "save")) {
2937 xmlShellSave(ctxt
, arg
, NULL
, NULL
);
2938 } else if (!strcmp(command
, "write")) {
2939 if ((arg
== NULL
) || (arg
[0] == 0))
2940 xmlGenericError(xmlGenericErrorContext
,
2941 "Write command requires a filename argument\n");
2943 xmlShellWrite(ctxt
, arg
, NULL
, NULL
);
2944 #endif /* LIBXML_OUTPUT_ENABLED */
2945 } else if (!strcmp(command
, "grep")) {
2946 xmlShellGrep(ctxt
, arg
, ctxt
->node
, NULL
);
2947 } else if (!strcmp(command
, "free")) {
2949 xmlMemShow(ctxt
->output
, 0);
2953 sscanf(arg
, "%d", &len
);
2954 xmlMemShow(ctxt
->output
, len
);
2956 } else if (!strcmp(command
, "pwd")) {
2959 if (!xmlShellPwd(ctxt
, dir
, ctxt
->node
, NULL
))
2960 fprintf(ctxt
->output
, "%s\n", dir
);
2961 } else if (!strcmp(command
, "du")) {
2962 xmlShellDu(ctxt
, NULL
, ctxt
->node
, NULL
);
2963 } else if (!strcmp(command
, "base")) {
2964 xmlShellBase(ctxt
, NULL
, ctxt
->node
, NULL
);
2965 } else if (!strcmp(command
, "set")) {
2966 xmlShellSetContent(ctxt
, arg
, ctxt
->node
, NULL
);
2967 #ifdef LIBXML_XPATH_ENABLED
2968 } else if (!strcmp(command
, "setns")) {
2970 xmlGenericError(xmlGenericErrorContext
,
2971 "setns: prefix=[nsuri] required\n");
2973 xmlShellRegisterNamespace(ctxt
, arg
, NULL
, NULL
);
2975 } else if (!strcmp(command
, "setrootns")) {
2978 root
= xmlDocGetRootElement(ctxt
->doc
);
2979 xmlShellRegisterRootNamespaces(ctxt
, NULL
, root
, NULL
);
2980 } else if (!strcmp(command
, "xpath")) {
2982 xmlGenericError(xmlGenericErrorContext
,
2983 "xpath: expression required\n");
2985 ctxt
->pctxt
->node
= ctxt
->node
;
2986 list
= xmlXPathEval((xmlChar
*) arg
, ctxt
->pctxt
);
2987 xmlXPathDebugDumpObject(ctxt
->output
, list
, 0);
2988 xmlXPathFreeObject(list
);
2990 #endif /* LIBXML_XPATH_ENABLED */
2991 #ifdef LIBXML_TREE_ENABLED
2992 } else if (!strcmp(command
, "setbase")) {
2993 xmlShellSetBase(ctxt
, arg
, ctxt
->node
, NULL
);
2995 } else if ((!strcmp(command
, "ls")) || (!strcmp(command
, "dir"))) {
2996 int dir
= (!strcmp(command
, "dir"));
3000 xmlShellDir(ctxt
, NULL
, ctxt
->node
, NULL
);
3002 xmlShellList(ctxt
, NULL
, ctxt
->node
, NULL
);
3004 ctxt
->pctxt
->node
= ctxt
->node
;
3005 #ifdef LIBXML_XPATH_ENABLED
3006 ctxt
->pctxt
->node
= ctxt
->node
;
3007 list
= xmlXPathEval((xmlChar
*) arg
, ctxt
->pctxt
);
3010 #endif /* LIBXML_XPATH_ENABLED */
3012 switch (list
->type
) {
3013 case XPATH_UNDEFINED
:
3014 xmlGenericError(xmlGenericErrorContext
,
3015 "%s: no such node\n", arg
);
3017 case XPATH_NODESET
:{
3020 if (list
->nodesetval
== NULL
)
3024 indx
< list
->nodesetval
->nodeNr
;
3027 xmlShellDir(ctxt
, NULL
,
3029 nodeTab
[indx
], NULL
);
3031 xmlShellList(ctxt
, NULL
,
3033 nodeTab
[indx
], NULL
);
3038 xmlGenericError(xmlGenericErrorContext
,
3039 "%s is a Boolean\n", arg
);
3042 xmlGenericError(xmlGenericErrorContext
,
3043 "%s is a number\n", arg
);
3046 xmlGenericError(xmlGenericErrorContext
,
3047 "%s is a string\n", arg
);
3050 xmlGenericError(xmlGenericErrorContext
,
3051 "%s is a point\n", arg
);
3054 xmlGenericError(xmlGenericErrorContext
,
3055 "%s is a range\n", arg
);
3057 case XPATH_LOCATIONSET
:
3058 xmlGenericError(xmlGenericErrorContext
,
3059 "%s is a range\n", arg
);
3062 xmlGenericError(xmlGenericErrorContext
,
3063 "%s is user-defined\n", arg
);
3065 case XPATH_XSLT_TREE
:
3066 xmlGenericError(xmlGenericErrorContext
,
3067 "%s is an XSLT value tree\n",
3071 #ifdef LIBXML_XPATH_ENABLED
3072 xmlXPathFreeObject(list
);
3075 xmlGenericError(xmlGenericErrorContext
,
3076 "%s: no such node\n", arg
);
3078 ctxt
->pctxt
->node
= NULL
;
3080 } else if (!strcmp(command
, "cd")) {
3082 ctxt
->node
= (xmlNodePtr
) ctxt
->doc
;
3084 #ifdef LIBXML_XPATH_ENABLED
3085 ctxt
->pctxt
->node
= ctxt
->node
;
3086 list
= xmlXPathEval((xmlChar
*) arg
, ctxt
->pctxt
);
3089 #endif /* LIBXML_XPATH_ENABLED */
3091 switch (list
->type
) {
3092 case XPATH_UNDEFINED
:
3093 xmlGenericError(xmlGenericErrorContext
,
3094 "%s: no such node\n", arg
);
3097 if (list
->nodesetval
!= NULL
) {
3098 if (list
->nodesetval
->nodeNr
== 1) {
3099 ctxt
->node
= list
->nodesetval
->nodeTab
[0];
3100 if ((ctxt
->node
!= NULL
) &&
3101 (ctxt
->node
->type
==
3102 XML_NAMESPACE_DECL
)) {
3103 xmlGenericError(xmlGenericErrorContext
,
3104 "cannot cd to namespace\n");
3108 xmlGenericError(xmlGenericErrorContext
,
3109 "%s is a %d Node Set\n",
3111 list
->nodesetval
->nodeNr
);
3113 xmlGenericError(xmlGenericErrorContext
,
3114 "%s is an empty Node Set\n",
3118 xmlGenericError(xmlGenericErrorContext
,
3119 "%s is a Boolean\n", arg
);
3122 xmlGenericError(xmlGenericErrorContext
,
3123 "%s is a number\n", arg
);
3126 xmlGenericError(xmlGenericErrorContext
,
3127 "%s is a string\n", arg
);
3130 xmlGenericError(xmlGenericErrorContext
,
3131 "%s is a point\n", arg
);
3134 xmlGenericError(xmlGenericErrorContext
,
3135 "%s is a range\n", arg
);
3137 case XPATH_LOCATIONSET
:
3138 xmlGenericError(xmlGenericErrorContext
,
3139 "%s is a range\n", arg
);
3142 xmlGenericError(xmlGenericErrorContext
,
3143 "%s is user-defined\n", arg
);
3145 case XPATH_XSLT_TREE
:
3146 xmlGenericError(xmlGenericErrorContext
,
3147 "%s is an XSLT value tree\n",
3151 #ifdef LIBXML_XPATH_ENABLED
3152 xmlXPathFreeObject(list
);
3155 xmlGenericError(xmlGenericErrorContext
,
3156 "%s: no such node\n", arg
);
3158 ctxt
->pctxt
->node
= NULL
;
3160 #ifdef LIBXML_OUTPUT_ENABLED
3161 } else if (!strcmp(command
, "cat")) {
3163 xmlShellCat(ctxt
, NULL
, ctxt
->node
, NULL
);
3165 ctxt
->pctxt
->node
= ctxt
->node
;
3166 #ifdef LIBXML_XPATH_ENABLED
3167 ctxt
->pctxt
->node
= ctxt
->node
;
3168 list
= xmlXPathEval((xmlChar
*) arg
, ctxt
->pctxt
);
3171 #endif /* LIBXML_XPATH_ENABLED */
3173 switch (list
->type
) {
3174 case XPATH_UNDEFINED
:
3175 xmlGenericError(xmlGenericErrorContext
,
3176 "%s: no such node\n", arg
);
3178 case XPATH_NODESET
:{
3181 if (list
->nodesetval
== NULL
)
3185 indx
< list
->nodesetval
->nodeNr
;
3188 fprintf(ctxt
->output
, " -------\n");
3189 xmlShellCat(ctxt
, NULL
,
3191 nodeTab
[indx
], NULL
);
3196 xmlGenericError(xmlGenericErrorContext
,
3197 "%s is a Boolean\n", arg
);
3200 xmlGenericError(xmlGenericErrorContext
,
3201 "%s is a number\n", arg
);
3204 xmlGenericError(xmlGenericErrorContext
,
3205 "%s is a string\n", arg
);
3208 xmlGenericError(xmlGenericErrorContext
,
3209 "%s is a point\n", arg
);
3212 xmlGenericError(xmlGenericErrorContext
,
3213 "%s is a range\n", arg
);
3215 case XPATH_LOCATIONSET
:
3216 xmlGenericError(xmlGenericErrorContext
,
3217 "%s is a range\n", arg
);
3220 xmlGenericError(xmlGenericErrorContext
,
3221 "%s is user-defined\n", arg
);
3223 case XPATH_XSLT_TREE
:
3224 xmlGenericError(xmlGenericErrorContext
,
3225 "%s is an XSLT value tree\n",
3229 #ifdef LIBXML_XPATH_ENABLED
3230 xmlXPathFreeObject(list
);
3233 xmlGenericError(xmlGenericErrorContext
,
3234 "%s: no such node\n", arg
);
3236 ctxt
->pctxt
->node
= NULL
;
3238 #endif /* LIBXML_OUTPUT_ENABLED */
3240 xmlGenericError(xmlGenericErrorContext
,
3241 "Unknown command %s\n", command
);
3243 free(cmdline
); /* not xmlFree here ! */
3246 #ifdef LIBXML_XPATH_ENABLED
3247 xmlXPathFreeContext(ctxt
->pctxt
);
3248 #endif /* LIBXML_XPATH_ENABLED */
3250 xmlFreeDoc(ctxt
->doc
);
3252 if (ctxt
->filename
!= NULL
)
3253 xmlFree(ctxt
->filename
);
3255 if (cmdline
!= NULL
)
3256 free(cmdline
); /* not xmlFree here ! */
3259 #endif /* LIBXML_XPATH_ENABLED */
3260 #define bottom_debugXML
3261 #include "elfgcchack.h"
3262 #endif /* LIBXML_DEBUG_ENABLED */