/*
* debugXML.c : This is a set of routines used for debugging the tree
* produced by the XML parser.
*
* See Copyright for the status of this software.
*
* Daniel Veillard <daniel@veillard.com>
*/
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_DEBUG_ENABLED
#include <string.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <libxml/xmlmemory.h>
#include <libxml/parserInternals.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/HTMLparser.h>
#include <libxml/xmlerror.h>
#include <libxml/xpathInternals.h>
#ifdef LIBXML_SCHEMAS_ENABLED
#endif
struct _xmlDebugCtxt {
};
static void
{
int i;
for (i = 0; i < 100; i++)
}
static void
{
/* remove the ATTRIBUTE_UNUSED when this is added */
}
/**
* xmlNsCheckScope:
* @node: the node
* @ns: the namespace node
*
* Check that a given namespace is in scope on a node.
*
* Returns 1 if in scope, -1 in case of argument error,
* -2 if the namespace is not in scope, and -3 if not on
* an ancestor node.
*/
static int
{
return(-1);
return(-2);
return(1);
return(-2);
}
}
}
/* the xml namespace may be declared on the document node */
return(1);
}
return(-3);
}
static void
{
return;
else
}
}
/**
* xmlDebugErr:
* @ctxt: a debug context
* @error: the error code
*
* Handle a debug error.
*/
static void
{
msg);
}
static void
{
}
static void
{
}
/**
* xmlCtxtNsCheckScope:
* @ctxt: the debugging context
* @node: the node
* @ns: the namespace node
*
* Report if a given namespace is is not in scope.
*/
static void
{
int ret;
if (ret == -2) {
"Reference to default namespace not in scope\n");
else
"Reference to namespace '%s' not in scope\n",
}
if (ret == -3) {
"Reference to default namespace not on ancestor\n");
else
"Reference to namespace '%s' not on ancestor\n",
}
}
/**
* xmlCtxtCheckString:
* @ctxt: the debug context
* @str: the string
*
* Do debugging on the string, currently it just checks the UTF-8 content
*/
static void
{
if (!xmlCheckUTF8(str)) {
"String is not UTF-8 %s", (const char *) str);
}
}
}
/**
* xmlCtxtCheckName:
* @ctxt: the debug context
* @name: the name
*
* Do debugging on the name, for example the dictionnary status and
* conformance to the Name production.
*/
static void
{
return;
}
if (xmlValidateName(name, 0)) {
"Name is not an NCName '%s'", (const char *) name);
}
"Name is not from the document dictionnary '%s'",
(const char *) name);
}
}
}
static void
"Node has no parent\n");
"Node has no doc\n");
} else {
#if 0
/* desactivated right now as it raises too many errors */
"Document has no dictionnary\n");
#endif
}
}
}
"Node doc differs from parent's one\n");
"Attr has no prev and not first of attr list\n");
"Node has no prev and not first of parent list\n");
} else {
"Node prev->next : back link wrong\n");
}
"Node has no next and not last of parent list\n");
} else {
"Node next->prev : forward link wrong\n");
"Node next->prev : forward link wrong\n");
}
}
}
}
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
break;
case XML_TEXT_NODE:
break;
/* some case of entity substitution can lead to this */
7)))
break;
"Text node has wrong name '%s'",
break;
case XML_COMMENT_NODE:
break;
"Comment node has wrong name '%s'",
break;
case XML_PI_NODE:
break;
case XML_CDATA_SECTION_NODE:
break;
"CData section has non NULL name '%s'",
break;
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
break;
}
}
static void
{
int i;
return;
}
/* TODO: check UTF8 content of the string */
return;
}
for (i = 0; i < 40; i++)
if (str[i] == 0)
return;
else if (IS_BLANK_CH(str[i]))
else if (str[i] >= 0x80)
else
}
static void
{
return;
}
"Node is not a DTD");
return;
}
else
}
/*
* Do a bit of checking
*/
}
static void
{
return;
}
"Node is not an attribute declaration");
return;
}
} else
"Node attribute declaration has no name");
} else
"Node attribute declaration has no element name");
case XML_ATTRIBUTE_CDATA:
break;
case XML_ATTRIBUTE_ID:
break;
case XML_ATTRIBUTE_IDREF:
break;
case XML_ATTRIBUTE_IDREFS:
break;
case XML_ATTRIBUTE_ENTITY:
break;
case XML_ATTRIBUTE_ENTITIES:
break;
case XML_ATTRIBUTE_NMTOKEN:
break;
case XML_ATTRIBUTE_NMTOKENS:
break;
break;
case XML_ATTRIBUTE_NOTATION:
break;
}
int indx;
if (indx != 0)
else
break;
}
else
}
case XML_ATTRIBUTE_NONE:
break;
case XML_ATTRIBUTE_REQUIRED:
break;
case XML_ATTRIBUTE_IMPLIED:
break;
case XML_ATTRIBUTE_FIXED:
break;
}
}
}
/*
* Do a bit of checking
*/
}
static void
{
return;
}
"Node is not an element declaration");
return;
}
}
} else
"Element declaration has no name");
break;
case XML_ELEMENT_TYPE_EMPTY:
break;
case XML_ELEMENT_TYPE_ANY:
break;
case XML_ELEMENT_TYPE_MIXED:
break;
case XML_ELEMENT_TYPE_ELEMENT:
break;
}
buf[0] = 0;
buf[5000] = 0;
}
}
/*
* Do a bit of checking
*/
}
static void
{
return;
}
"Node is not an entity declaration");
return;
}
}
} else
"Entity declaration has no name");
break;
break;
break;
break;
break;
break;
}
if (ent->ExternalID) {
(char *) ent->ExternalID);
}
}
}
}
}
/*
* Do a bit of checking
*/
}
static void
{
return;
}
"Node is not a namespace declaration");
return;
}
"Incomplete namespace %s href=NULL\n",
else
"Incomplete default namespace href=NULL\n");
} else {
else
}
}
}
static void
{
}
}
static void
{
return;
}
break;
break;
break;
break;
break;
default:
}
if (ent->ExternalID) {
(char *) ent->ExternalID);
}
}
}
}
}
}
/**
* xmlCtxtDumpAttr:
* @output: the FILE * for the output
* @attr: the attribute
* @depth: the indentation level.
*
* Dumps debug information for the attribute
*/
static void
{
return;
}
}
}
"Attribute has no name");
/*
* Do a bit of checking
*/
}
/**
* xmlCtxtDumpAttrList:
* @output: the FILE * for the output
* @attr: the attribute list
* @depth: the indentation level.
*
* Dumps debug information for the attribute list
*/
static void
{
}
}
/**
* xmlCtxtDumpOneNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is not recursive
*/
static void
{
}
return;
}
case XML_ELEMENT_NODE:
}
}
break;
case XML_ATTRIBUTE_NODE:
return;
case XML_TEXT_NODE:
else
else
} else
}
break;
case XML_CDATA_SECTION_NODE:
}
break;
case XML_ENTITY_REF_NODE:
}
break;
case XML_ENTITY_NODE:
}
break;
case XML_PI_NODE:
}
break;
case XML_COMMENT_NODE:
}
break;
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
}
return;
case XML_DOCUMENT_TYPE_NODE:
}
break;
case XML_DOCUMENT_FRAG_NODE:
}
break;
case XML_NOTATION_NODE:
}
break;
case XML_DTD_NODE:
return;
case XML_ELEMENT_DECL:
return;
case XML_ATTRIBUTE_DECL:
return;
case XML_ENTITY_DECL:
return;
case XML_NAMESPACE_DECL:
return;
case XML_XINCLUDE_START:
}
return;
case XML_XINCLUDE_END:
}
return;
default:
return;
}
}
}
}
}
} else {
}
/*
* Do a bit of checking
*/
}
/**
* xmlCtxtDumpNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is recursive
*/
static void
{
}
return;
}
}
}
/**
* xmlCtxtDumpNodeList:
* @output: the FILE * for the output
* @node: the node list
* @depth: the indentation level.
*
* Dumps debug information for the list of element node, it is recursive
*/
static void
{
}
}
static void
{
return;
}
case XML_ELEMENT_NODE:
"Misplaced ELEMENT node\n");
break;
case XML_ATTRIBUTE_NODE:
"Misplaced ATTRIBUTE node\n");
break;
case XML_TEXT_NODE:
"Misplaced TEXT node\n");
break;
case XML_CDATA_SECTION_NODE:
"Misplaced CDATA node\n");
break;
case XML_ENTITY_REF_NODE:
"Misplaced ENTITYREF node\n");
break;
case XML_ENTITY_NODE:
"Misplaced ENTITY node\n");
break;
case XML_PI_NODE:
"Misplaced PI node\n");
break;
case XML_COMMENT_NODE:
"Misplaced COMMENT node\n");
break;
case XML_DOCUMENT_NODE:
break;
case XML_HTML_DOCUMENT_NODE:
break;
case XML_DOCUMENT_TYPE_NODE:
"Misplaced DOCTYPE node\n");
break;
case XML_DOCUMENT_FRAG_NODE:
"Misplaced FRAGMENT node\n");
break;
case XML_NOTATION_NODE:
"Misplaced NOTATION node\n");
break;
default:
}
}
/**
* xmlCtxtDumpDocumentHead:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information cncerning the document, not recursive
*/
static void
{
}
}
}
}
if (doc->standalone)
}
}
/**
* xmlCtxtDumpDocument:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for the document, it's recursive
*/
static void
{
return;
}
}
}
static void
{
return;
}
break;
break;
break;
break;
break;
default:
}
}
}
/**
* xmlCtxtDumpEntities:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for all the entities in use by the document
*/
static void
{
ctxt);
} else
ctxt);
}
/**
* xmlCtxtDumpDTD:
* @output: the FILE * for the output
* @dtd: the DTD
*
* Dumps debug information for the DTD
*/
static void
{
return;
}
else {
}
}
/************************************************************************
* *
* Public entry points for dump *
* *
************************************************************************/
/**
* xmlDebugDumpString:
* @output: the FILE * for the output
* @str: the string
*
* Dumps informations about the string, shorten it if necessary
*/
void
{
int i;
return;
}
for (i = 0; i < 40; i++)
if (str[i] == 0)
return;
else if (IS_BLANK_CH(str[i]))
else if (str[i] >= 0x80)
else
}
/**
* xmlDebugDumpAttr:
* @output: the FILE * for the output
* @attr: the attribute
* @depth: the indentation level.
*
* Dumps debug information for the attribute
*/
void
}
/**
* xmlDebugDumpEntities:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for all the entities in use by the document
*/
void
{
}
/**
* xmlDebugDumpAttrList:
* @output: the FILE * for the output
* @attr: the attribute list
* @depth: the indentation level.
*
* Dumps debug information for the attribute list
*/
void
{
}
/**
* xmlDebugDumpOneNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is not recursive
*/
void
{
}
/**
* xmlDebugDumpNode:
* @output: the FILE * for the output
* @node: the node
* @depth: the indentation level.
*
* Dumps debug information for the element node, it is recursive
*/
void
{
}
/**
* xmlDebugDumpNodeList:
* @output: the FILE * for the output
* @node: the node list
* @depth: the indentation level.
*
* Dumps debug information for the list of element node, it is recursive
*/
void
{
}
/**
* xmlDebugDumpDocumentHead:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information cncerning the document, not recursive
*/
void
{
}
/**
* xmlDebugDumpDocument:
* @output: the FILE * for the output
* @doc: the document
*
* Dumps debug information for the document, it's recursive
*/
void
{
}
/**
* xmlDebugDumpDTD:
* @output: the FILE * for the output
* @dtd: the DTD
*
* Dumps debug information for the DTD
*/
void
{
}
/************************************************************************
* *
* Public entry points for checkings *
* *
************************************************************************/
/**
* xmlDebugCheckDocument:
* @output: the FILE * for the output
* @doc: the document
*
* Check the document for potential content problems, and output
* the errors to @output
*
* Returns the number of errors found
*/
int
{
}
/************************************************************************
* *
* Helpers for Shell *
* *
************************************************************************/
/**
* xmlLsCountNode:
* @node: the node to count
*
* Count the children of @node.
*
* Returns the number of children of @node.
*/
int
int ret = 0;
return(0);
case XML_ELEMENT_NODE:
break;
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
break;
case XML_ATTRIBUTE_NODE:
break;
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
}
break;
case XML_ENTITY_REF_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
ret = 1;
break;
}
return(ret);
}
/**
* xmlLsOneNode:
* @output: the FILE * for the output
* @node: the node to dump
*
* Dump to @output the type and name of @node.
*/
void
return;
}
case XML_ELEMENT_NODE:
break;
case XML_ATTRIBUTE_NODE:
break;
case XML_TEXT_NODE:
break;
case XML_CDATA_SECTION_NODE:
break;
case XML_ENTITY_REF_NODE:
break;
case XML_ENTITY_NODE:
break;
case XML_PI_NODE:
break;
case XML_COMMENT_NODE:
break;
case XML_DOCUMENT_NODE:
break;
case XML_HTML_DOCUMENT_NODE:
break;
case XML_DOCUMENT_TYPE_NODE:
break;
case XML_DOCUMENT_FRAG_NODE:
break;
case XML_NOTATION_NODE:
break;
case XML_NAMESPACE_DECL:
break;
default:
}
else
else
}
case XML_ELEMENT_NODE:
break;
case XML_ATTRIBUTE_NODE:
break;
case XML_TEXT_NODE:
}
break;
case XML_CDATA_SECTION_NODE:
break;
case XML_ENTITY_REF_NODE:
break;
case XML_ENTITY_NODE:
break;
case XML_PI_NODE:
break;
case XML_COMMENT_NODE:
break;
case XML_DOCUMENT_NODE:
break;
case XML_HTML_DOCUMENT_NODE:
break;
case XML_DOCUMENT_TYPE_NODE:
break;
case XML_DOCUMENT_FRAG_NODE:
break;
case XML_NOTATION_NODE:
break;
case XML_NAMESPACE_DECL: {
else
break;
}
default:
}
}
/**
* xmlBoolToText:
* @boolval: a bool to turn into text
*
* Convenient way to turn bool into text
*
* Returns a pointer to either "True" or "False"
*/
const char *
{
if (boolval)
return("True");
else
return("False");
}
#ifdef LIBXML_XPATH_ENABLED
/****************************************************************
* *
* The XML shell related functions *
* *
****************************************************************/
/*
* TODO: Improvement/cleanups for the XML shell
* - allow to shell out an editor on a subpart
* - cleanup function registrations (with help) and calling
* - provide registration routines
*/
/**
* xmlShellPrintXPathError:
* @errorType: valid xpath error id
* @arg: the argument that cause xpath to fail
*
* Print the xpath error to libxml default error channel
*/
void
{
if (!arg)
arg = default_arg;
switch (errorType) {
case XPATH_UNDEFINED:
"%s: no such node\n", arg);
break;
case XPATH_BOOLEAN:
"%s is a Boolean\n", arg);
break;
case XPATH_NUMBER:
"%s is a number\n", arg);
break;
case XPATH_STRING:
"%s is a string\n", arg);
break;
case XPATH_POINT:
"%s is a point\n", arg);
break;
case XPATH_RANGE:
"%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
"%s is a range\n", arg);
break;
case XPATH_USERS:
"%s is user-defined\n", arg);
break;
case XPATH_XSLT_TREE:
"%s is an XSLT value tree\n", arg);
break;
}
#if 0
"Try casting the result string function (xpath builtin)\n",
arg);
#endif
}
#ifdef LIBXML_OUTPUT_ENABLED
/**
* xmlShellPrintNodeCtxt:
* @ctxt : a non-null shell context
* @node : a non-null node to print to the output FILE
*
* Print node to the output FILE
*/
static void
{
if (!node)
return;
else
else
}
/**
* xmlShellPrintNode:
* @node : a non-null node to print to the output FILE
*
* Print node to the output FILE
*/
void
{
}
#endif /* LIBXML_OUTPUT_ENABLED */
/**
* xmlShellPrintXPathResultCtxt:
* @ctxt: a valid shell context
* @list: a valid result generated by an xpath evaluation
*
* Prints result to the output FILE
*/
static void
{
if (!ctxt)
return;
case XPATH_NODESET:{
#ifdef LIBXML_OUTPUT_ENABLED
int indx;
if (list->nodesetval) {
indx++) {
}
} else {
"Empty node set\n");
}
break;
#else
"Node set\n");
#endif /* LIBXML_OUTPUT_ENABLED */
}
case XPATH_BOOLEAN:
"Is a Boolean:%s\n",
break;
case XPATH_NUMBER:
break;
case XPATH_STRING:
break;
default:
}
}
}
/**
* xmlShellPrintXPathResult:
* @list: a valid result generated by an xpath evaluation
*
* Prints result to the output FILE
*/
void
{
}
/**
* xmlShellList:
* @ctxt: the shell context
* @arg: unused
* @node: a node
* @node2: unused
*
* Implements the XML shell function "ls"
* Does an Unix like listing of the given node (like a directory)
*
* Returns 0
*/
int
{
if (!ctxt)
return (0);
return (0);
}
return (0);
} else {
return (0);
}
}
return (0);
}
/**
* xmlShellBase:
* @ctxt: the shell context
* @arg: unused
* @node: a node
* @node2: unused
*
* Implements the XML shell function "base"
* dumps the current XML base of the node
*
* Returns 0
*/
int
{
if (!ctxt)
return 0;
return (0);
}
} else {
}
return (0);
}
#ifdef LIBXML_TREE_ENABLED
/**
* xmlShellSetBase:
* @ctxt: the shell context
* @arg: the new base
* @node: a node
* @node2: unused
*
* Implements the XML shell function "setbase"
* change the current XML base of the node
*
* Returns 0
*/
static int
{
return (0);
}
#endif
#ifdef LIBXML_XPATH_ENABLED
/**
* xmlShellRegisterNamespace:
* @ctxt: the shell context
* @arg: a string in prefix=nsuri format
* @node: unused
* @node2: unused
*
* Implements the XML shell function "setns"
* register/unregister a prefix=namespace pair
* on the XPath context
*
* Returns 0 on success and a negative value otherwise.
*/
static int
{
/* skip spaces */
/*while((*next) == ' ') next++;*/
if((*next) == '\0') break;
/* find prefix */
return(-1);
}
*(next++) = '\0';
/* find href */
*(next++) = '\0';
}
/* do register namespace */
fprintf(ctxt->output,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
return(-1);
}
}
return(0);
}
/**
* xmlShellRegisterRootNamespaces:
* @ctxt: the shell context
* @arg: unused
* @node: the root element
* @node2: unused
*
* Implements the XML shell function "setrootns"
* which registers all namespaces declarations found on the root element.
*
* Returns 0 on success and a negative value otherwise.
*/
static int
{
return(-1);
else
}
return(0);
}
#endif
/**
* xmlShellGrep:
* @ctxt: the shell context
* @arg: the string or regular expression to find
* @node: a node
* @node2: unused
*
* Implements the XML shell function "grep"
* dumps informations about the node (namespace, attributes, content).
*
* Returns 0
*/
static int
{
if (!ctxt)
return (0);
return (0);
return (0);
#ifdef LIBXML_REGEXP_ENABLED
}
#endif
}
}
}
/*
* Browse the full subtree, deep first
*/
/* deep first */
/* then siblings */
} else {
/* go up to parents->next if needed */
}
break;
}
break;
}
}
}
}
return (0);
}
/**
* xmlShellDir:
* @ctxt: the shell context
* @arg: unused
* @node: a node
* @node2: unused
*
* Implements the XML shell function "dir"
* dumps informations about the node (namespace, attributes, content).
*
* Returns 0
*/
int
{
if (!ctxt)
return (0);
return (0);
}
} else {
}
return (0);
}
/**
* xmlShellSetContent:
* @ctxt: the shell context
* @value: the content as a string
* @node: a node
* @node2: unused
*
* Implements the XML shell function "dir"
* dumps informations about the node (namespace, attributes, content).
*
* Returns 0
*/
static int
{
if (!ctxt)
return (0);
return (0);
}
return (0);
}
if (ret == XML_ERR_OK) {
}
} else {
}
return (0);
}
#ifdef LIBXML_SCHEMAS_ENABLED
/**
* xmlShellRNGValidate:
* @ctxt: the shell context
* @schemas: the path to the Relax-NG schemas
* @node: a node
* @node2: unused
*
* Implements the XML shell function "relaxng"
* validating the instance against a Relax-NG schemas
*
* Returns 0
*/
static int
{
int ret;
stderr);
if (relaxngschemas == NULL) {
"Relax-NG schema %s failed to compile\n", schemas);
return(-1);
}
stderr);
if (ret == 0) {
} else if (ret > 0) {
} else {
}
if (relaxngschemas != NULL)
return(0);
}
#endif
#ifdef LIBXML_OUTPUT_ENABLED
/**
* xmlShellCat:
* @ctxt: the shell context
* @arg: unused
* @node: a node
* @node2: unused
*
* Implements the XML shell function "cat"
* dumps the serialization node content (XML or HTML).
*
* Returns 0
*/
int
{
if (!ctxt)
return (0);
return (0);
}
#ifdef LIBXML_HTML_ENABLED
else
#else
else
#endif /* LIBXML_HTML_ENABLED */
} else {
else
}
return (0);
}
#endif /* LIBXML_OUTPUT_ENABLED */
/**
* xmlShellLoad:
* @ctxt: the shell context
* @filename: the file name
* @node: unused
* @node2: unused
*
* Implements the XML shell function "load"
* loads a new document specified by the filename
*
* Returns 0 or -1 if loading failed
*/
int
{
int html = 0;
if (html) {
#ifdef LIBXML_HTML_ENABLED
#else
#endif /* LIBXML_HTML_ENABLED */
} else {
}
}
#ifdef LIBXML_XPATH_ENABLED
#endif /* LIBXML_XPATH_ENABLED */
#ifdef LIBXML_XPATH_ENABLED
#endif /* LIBXML_XPATH_ENABLED */
} else
return (-1);
return (0);
}
#ifdef LIBXML_OUTPUT_ENABLED
/**
* xmlShellWrite:
* @ctxt: the shell context
* @filename: the file name
* @node: a node in the tree
* @node2: unused
*
* Implements the XML shell function "write"
* Write the current node to the filename, it saves the serialization
* of the subtree under the @node specified
*
* Returns 0 or -1 in case of error
*/
int
{
return (-1);
return (-1);
}
#ifdef W_OK
"Cannot write to %s\n", filename);
return (-1);
}
#endif
case XML_DOCUMENT_NODE:
"Failed to write to %s\n", filename);
return (-1);
}
break;
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_HTML_ENABLED
"Failed to write to %s\n", filename);
return (-1);
}
#else
"Failed to write to %s\n", filename);
return (-1);
}
#endif /* LIBXML_HTML_ENABLED */
break;
default:{
FILE *f;
if (f == NULL) {
"Failed to write to %s\n", filename);
return (-1);
}
fclose(f);
}
}
return (0);
}
/**
* xmlShellSave:
* @ctxt: the shell context
* @filename: the file name (optional)
* @node: unused
* @node2: unused
*
* Implements the XML shell function "save"
* Write the current document to the filename, or it's original name
*
* Returns 0 or -1 in case of error
*/
int
{
return (-1);
return (-1);
#ifdef W_OK
"Cannot save to %s\n", filename);
return (-1);
}
#endif
case XML_DOCUMENT_NODE:
"Failed to save to %s\n", filename);
}
break;
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_HTML_ENABLED
"Failed to save to %s\n", filename);
}
#else
"Failed to save to %s\n", filename);
}
#endif /* LIBXML_HTML_ENABLED */
break;
default:
"To save to subparts of a document use the 'write' command\n");
return (-1);
}
return (0);
}
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_VALID_ENABLED
/**
* xmlShellValidate:
* @ctxt: the shell context
* @dtd: the DTD URI (optional)
* @node: unused
* @node2: unused
*
* Implements the XML shell function "validate"
* Validate the document, if a DTD path is provided, then the validation
* is done against the given DTD.
*
* Returns 0 or -1 in case of error
*/
int
{
} else {
}
}
return (res);
}
#endif /* LIBXML_VALID_ENABLED */
/**
* xmlShellDu:
* @ctxt: the shell context
* @arg: unused
* @tree: a node defining a subtree
* @node2: unused
*
* Implements the XML shell function "du"
* show the structure of the subtree under node @tree
* If @tree is null, the command works on the current node.
*
* Returns 0 or -1 in case of error
*/
int
{
int indent = 0, i;
if (!ctxt)
return (-1);
return (-1);
for (i = 0; i < indent; i++)
} else {
}
/*
* Browse the full subtree, deep first
*/
/* deep first */
indent++;
/* then siblings */
/* go up to parents->next if needed */
indent--;
}
break;
}
break;
}
break;
}
}
/* exit condition */
} else
}
return (0);
}
/**
* xmlShellPwd:
* @ctxt: the shell context
* @buffer: the output buffer
* @node: a node
* @node2: unused
*
* Implements the XML shell function "pwd"
* Show the full path from the root to the node, if needed building
* thumblers when similar elements exists at a given ancestor level.
* The output is compatible with XPath commands.
*
* Returns 0 or -1 in case of error
*/
int
{
return (-1);
return (-1);
/*
* This test prevents buffer overflow, because this routine
* is only called by xmlShell, in which the second argument is
* 500 chars long.
* It is a dirty hack before a cleaner solution is found.
* Documentation should mention that the second argument must
* be at least 500 chars long, and could be stripped if too long.
*/
return (0);
}
/**
* xmlShell:
* @doc: the initial document
* @filename: the output buffer
* @input: the line reading function
* @output: the output FILE*, defaults to stdout if NULL
*
* Implements the XML shell
* This allow to load, validate, view, modify and save a document
* using a environment similar to a UNIX commandline.
*/
void
{
int nbargs;
int i;
return;
return;
return;
return;
#ifdef LIBXML_XPATH_ENABLED
return;
}
#endif /* LIBXML_XPATH_ENABLED */
while (1) {
else
/*
* Get a new command line
*/
break;
/*
* Parse the command itself
*/
nbargs = 0;
cur++;
i = 0;
if (*cur == 0)
break;
}
command[i] = 0;
if (i == 0)
continue;
nbargs++;
/*
* Parse the argument
*/
cur++;
i = 0;
if (*cur == 0)
break;
}
arg[i] = 0;
if (i != 0)
nbargs++;
/*
* start interpreting the command
*/
break;
break;
break;
fprintf(ctxt->output, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n");
fprintf(ctxt->output, "\tdu [path] show the structure of the subtree under path or the current node\n");
fprintf(ctxt->output, "\tset xml_fragment replace the current node content with the fragment parsed in context\n");
#ifdef LIBXML_XPATH_ENABLED
fprintf(ctxt->output, "\txpath expr evaluate the XPath expression in that context and print the result\n");
fprintf(ctxt->output, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n");
#endif /* LIBXML_XPATH_ENABLED */
#ifdef LIBXML_OUTPUT_ENABLED
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_VALID_ENABLED
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED
#endif
#ifdef LIBXML_VALID_ENABLED
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED
#endif
#ifdef LIBXML_OUTPUT_ENABLED
"Write command requires a filename argument\n");
else
#endif /* LIBXML_OUTPUT_ENABLED */
if (arg[0] == 0) {
} else {
int len = 0;
}
#ifdef LIBXML_XPATH_ENABLED
if (arg[0] == 0) {
"setns: prefix=[nsuri] required\n");
} else {
}
if (arg[0] == 0) {
"xpath: expression required\n");
} else {
}
#endif /* LIBXML_XPATH_ENABLED */
#ifdef LIBXML_TREE_ENABLED
#endif
if (arg[0] == 0) {
if (dir)
else
} else {
#ifdef LIBXML_XPATH_ENABLED
#else
#endif /* LIBXML_XPATH_ENABLED */
case XPATH_UNDEFINED:
"%s: no such node\n", arg);
break;
case XPATH_NODESET:{
int indx;
break;
for (indx = 0;
indx++) {
if (dir)
list->nodesetval->
else
list->nodesetval->
}
break;
}
case XPATH_BOOLEAN:
"%s is a Boolean\n", arg);
break;
case XPATH_NUMBER:
"%s is a number\n", arg);
break;
case XPATH_STRING:
"%s is a string\n", arg);
break;
case XPATH_POINT:
"%s is a point\n", arg);
break;
case XPATH_RANGE:
"%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
"%s is a range\n", arg);
break;
case XPATH_USERS:
"%s is user-defined\n", arg);
break;
case XPATH_XSLT_TREE:
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED
#endif
} else {
"%s: no such node\n", arg);
}
}
if (arg[0] == 0) {
} else {
#ifdef LIBXML_XPATH_ENABLED
#else
#endif /* LIBXML_XPATH_ENABLED */
case XPATH_UNDEFINED:
"%s: no such node\n", arg);
break;
case XPATH_NODESET:
"cannot cd to namespace\n");
}
} else
"%s is a %d Node Set\n",
arg,
} else
"%s is an empty Node Set\n",
arg);
break;
case XPATH_BOOLEAN:
"%s is a Boolean\n", arg);
break;
case XPATH_NUMBER:
"%s is a number\n", arg);
break;
case XPATH_STRING:
"%s is a string\n", arg);
break;
case XPATH_POINT:
"%s is a point\n", arg);
break;
case XPATH_RANGE:
"%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
"%s is a range\n", arg);
break;
case XPATH_USERS:
"%s is user-defined\n", arg);
break;
case XPATH_XSLT_TREE:
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED
#endif
} else {
"%s: no such node\n", arg);
}
}
#ifdef LIBXML_OUTPUT_ENABLED
if (arg[0] == 0) {
} else {
#ifdef LIBXML_XPATH_ENABLED
#else
#endif /* LIBXML_XPATH_ENABLED */
case XPATH_UNDEFINED:
"%s: no such node\n", arg);
break;
case XPATH_NODESET:{
int indx;
break;
for (indx = 0;
indx++) {
if (i > 0)
list->nodesetval->
}
break;
}
case XPATH_BOOLEAN:
"%s is a Boolean\n", arg);
break;
case XPATH_NUMBER:
"%s is a number\n", arg);
break;
case XPATH_STRING:
"%s is a string\n", arg);
break;
case XPATH_POINT:
"%s is a point\n", arg);
break;
case XPATH_RANGE:
"%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
"%s is a range\n", arg);
break;
case XPATH_USERS:
"%s is user-defined\n", arg);
break;
case XPATH_XSLT_TREE:
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED
#endif
} else {
"%s: no such node\n", arg);
}
}
#endif /* LIBXML_OUTPUT_ENABLED */
} else {
"Unknown command %s\n", command);
}
}
#ifdef LIBXML_XPATH_ENABLED
#endif /* LIBXML_XPATH_ENABLED */
}
}
#endif /* LIBXML_XPATH_ENABLED */
#define bottom_debugXML
#include "elfgcchack.h"
#endif /* LIBXML_DEBUG_ENABLED */