aboutsummaryrefslogtreecommitdiffstats
path: root/debugXML.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-06-16 14:08:33 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-06-16 14:08:33 +0000
commitbbaa997a06eef7198af749649a3aac4fc6cff0c5 (patch)
tree4f9de05fdfb78508f9d3a10d78c65c9f3abc8deb /debugXML.c
parent4a14fb8fa27c0e954fcc78be4de4a6e82de400dc (diff)
downloadandroid_external_libxml2-bbaa997a06eef7198af749649a3aac4fc6cff0c5.tar.gz
android_external_libxml2-bbaa997a06eef7198af749649a3aac4fc6cff0c5.tar.bz2
android_external_libxml2-bbaa997a06eef7198af749649a3aac4fc6cff0c5.zip
applied patch from Stefano Debenedetti to register namespaces in the debug
* debugXML.c: applied patch from Stefano Debenedetti to register namespaces in the debug shell Daniel
Diffstat (limited to 'debugXML.c')
-rw-r--r--debugXML.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/debugXML.c b/debugXML.c
index 6886ee8d..768010d1 100644
--- a/debugXML.c
+++ b/debugXML.c
@@ -1561,6 +1561,66 @@ xmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
}
#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
+xmlShellRegisterNamespace(xmlShellCtxtPtr ctxt, char *arg,
+ xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node2 ATTRIBUTE_UNUSED)
+{
+ xmlChar* nsListDup;
+ xmlChar* prefix;
+ xmlChar* href;
+ xmlChar* next;
+
+ nsListDup = xmlStrdup((xmlChar *) arg);
+ next = nsListDup;
+ while(next != NULL) {
+ /* skip spaces */
+ /*while((*next) == ' ') next++;*/
+ if((*next) == '\0') break;
+
+ /* find prefix */
+ prefix = next;
+ next = (xmlChar*)xmlStrchr(next, '=');
+ if(next == NULL) {
+ fprintf(ctxt->output, "setns: prefix=[nsuri] required\n");
+ xmlFree(nsListDup);
+ return(-1);
+ }
+ *(next++) = '\0';
+
+ /* find href */
+ href = next;
+ next = (xmlChar*)xmlStrchr(next, ' ');
+ if(next != NULL) {
+ *(next++) = '\0';
+ }
+
+ /* do register namespace */
+ if(xmlXPathRegisterNs(ctxt->pctxt, prefix, href) != 0) {
+ fprintf(ctxt->output,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
+ xmlFree(nsListDup);
+ return(-1);
+ }
+ }
+
+ xmlFree(nsListDup);
+ return(0);
+}
+#endif
+
/**
* xmlShellGrep:
* @ctxt: the shell context
@@ -2246,6 +2306,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
fprintf(ctxt->output, "\tls [path] list contents of path or the current directory\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");
+ fprintf(ctxt->output, "\t format for nsreg is: prefix=[nsuri] (i.e. prefix= unsets a prefix)\n");
#endif /* LIBXML_XPATH_ENABLED */
fprintf(ctxt->output, "\tpwd display current working directory\n");
fprintf(ctxt->output, "\tquit leave shell\n");
@@ -2297,6 +2359,13 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
} else if (!strcmp(command, "base")) {
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
#ifdef LIBXML_XPATH_ENABLED
+ } else if (!strcmp(command, "setns")) {
+ if (arg[0] == 0) {
+ xmlGenericError(xmlGenericErrorContext,
+ "setns: prefix=[nsuri] required\n");
+ } else {
+ xmlShellRegisterNamespace(ctxt, arg, NULL, NULL);
+ }
} else if (!strcmp(command, "xpath")) {
if (arg[0] == 0) {
xmlGenericError(xmlGenericErrorContext,