[libxml2] Improve xmllint shell
- From: Daniel Veillard <veillard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Improve xmllint shell
- Date: Mon, 7 May 2012 09:05:12 +0000 (UTC)
commit 40db1eeb3637af933fca491dfc90c25c31e6e05e
Author: Ryan <s covich gmail com>
Date: Mon May 7 17:04:04 2012 +0800
Improve xmllint shell
For https://bugzilla.gnome.org/show_bug.cgi?id=310222
adds namespace support to ls, du and the element named in
the command shell prompt. It also fixes du to actually dump
the requested path, if the user gives one, rather than always
dumping the whole file.
debugXML.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/debugXML.c b/debugXML.c
index c26217a..30ca6c2 100644
--- a/debugXML.c
+++ b/debugXML.c
@@ -1724,8 +1724,11 @@ xmlLsOneNode(FILE *output, xmlNodePtr node) {
switch (node->type) {
case XML_ELEMENT_NODE:
- if (node->name != NULL)
+ if (node->name != NULL) {
+ if ((node->ns != NULL) && (node->ns->prefix != NULL))
+ fprintf(output, "%s:", node->ns->prefix);
fprintf(output, "%s", (const char *) node->name);
+ }
break;
case XML_ATTRIBUTE_NODE:
if (node->name != NULL)
@@ -2696,6 +2699,8 @@ xmlShellDu(xmlShellCtxtPtr ctxt,
} else if (node->type == XML_ELEMENT_NODE) {
for (i = 0; i < indent; i++)
fprintf(ctxt->output, " ");
+ if ((node->ns) && (node->ns->prefix))
+ fprintf(ctxt->output, "%s:", node->ns->prefix);
fprintf(ctxt->output, "%s\n", node->name);
} else {
}
@@ -2837,6 +2842,10 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
while (1) {
if (ctxt->node == (xmlNodePtr) ctxt->doc)
snprintf(prompt, sizeof(prompt), "%s > ", "/");
+ else if ((ctxt->node != NULL) && (ctxt->node->name) &&
+ (ctxt->node->ns) && (ctxt->node->ns->prefix))
+ snprintf(prompt, sizeof(prompt), "%s:%s > ",
+ (ctxt->node->ns->prefix), ctxt->node->name);
else if ((ctxt->node != NULL) && (ctxt->node->name))
snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
else
@@ -2960,7 +2969,79 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
fprintf(ctxt->output, "%s\n", dir);
} else if (!strcmp(command, "du")) {
- xmlShellDu(ctxt, NULL, ctxt->node, NULL);
+ if (arg[0] == 0) {
+ xmlShellDu(ctxt, NULL, ctxt->node, NULL);
+ } else {
+ ctxt->pctxt->node = ctxt->node;
+#ifdef LIBXML_XPATH_ENABLED
+ ctxt->pctxt->node = ctxt->node;
+ list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
+#else
+ list = NULL;
+#endif /* LIBXML_XPATH_ENABLED */
+ if (list != NULL) {
+ switch (list->type) {
+ case XPATH_UNDEFINED:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ break;
+ case XPATH_NODESET:{
+ int indx;
+
+ if (list->nodesetval == NULL)
+ break;
+
+ for (indx = 0;
+ indx < list->nodesetval->nodeNr;
+ indx++)
+ xmlShellDu(ctxt, NULL,
+ list->nodesetval->
+ nodeTab[indx], NULL);
+ break;
+ }
+ case XPATH_BOOLEAN:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a Boolean\n", arg);
+ break;
+ case XPATH_NUMBER:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a number\n", arg);
+ break;
+ case XPATH_STRING:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a string\n", arg);
+ break;
+ case XPATH_POINT:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a point\n", arg);
+ break;
+ case XPATH_RANGE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_LOCATIONSET:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_USERS:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is user-defined\n", arg);
+ break;
+ case XPATH_XSLT_TREE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is an XSLT value tree\n",
+ arg);
+ break;
+ }
+#ifdef LIBXML_XPATH_ENABLED
+ xmlXPathFreeObject(list);
+#endif
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ }
+ ctxt->pctxt->node = NULL;
+ }
} else if (!strcmp(command, "base")) {
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
} else if (!strcmp(command, "set")) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]