Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

default namespaces now work

  • Loading branch information...
commit 4a762e2c6f3f8961c19792be022d71f4f4e1a394 1 parent f1e2716
Kyle Maxwell authored
View
1  Makefile.am
@@ -62,3 +62,4 @@ check-am:
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."
@echo "div..."; ./parsley test/div.let test/div.html 2>&1 | diff test/div.json - && echo " success."
+ @echo "default-namespace..."; ./parsley -x test/default-namespace.let test/default-namespace.xml 2>&1 | diff test/default-namespace.json - && echo " success."
View
1  Makefile.in
@@ -761,6 +761,7 @@ check-am:
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."
@echo "div..."; ./parsley test/div.let test/div.html 2>&1 | diff test/div.json - && echo " success."
+ @echo "default-namespace..."; ./parsley -x test/default-namespace.let test/default-namespace.xml 2>&1 | diff test/default-namespace.json - && echo " success."
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
View
39 parsley.c
@@ -400,8 +400,47 @@ parsleyXsltError(void * ctx, const char * msg, ...) {
va_end(ap);
}
+static bool
+hasDefaultNS(xmlDocPtr doc) {
+ return xmlSearchNs(doc, doc->children, NULL) != NULL;
+}
+
+static void
+_killDefaultNS(xmlNodePtr node) {
+ if(node == NULL) return;
+
+ xmlNsPtr ns = node->nsDef;
+ if(ns != NULL) {
+ if(ns->prefix == NULL) node->nsDef = ns->next;
+ xmlNsPtr prev = ns;
+ while(ns = ns->next) {
+ if(ns->prefix == NULL) prev->next = ns->next;
+ }
+ }
+
+ ns = node->ns;
+ if(ns != NULL) {
+ if(ns->prefix == NULL) node->ns = ns->next;
+ xmlNsPtr prev = ns;
+ while(ns = ns->next) {
+ if(ns->prefix == NULL) prev->next = ns->next;
+ }
+ }
+
+ _killDefaultNS(node->children);
+ _killDefaultNS(node->next);
+}
+
+void
+killDefaultNS(xmlDocPtr doc) {
+ if(hasDefaultNS(doc)) {
+ _killDefaultNS(doc->children);
+ }
+}
parsedParsleyPtr parsley_parse_doc(parsleyPtr parsley, xmlDocPtr doc, int flags) {
+ killDefaultNS(doc);
+
parsedParsleyPtr ptr = (parsedParsleyPtr) calloc(sizeof(parsed_parsley), 1);
ptr->error = NULL;
ptr->parsley = parsley;
View
1  parsley.h
@@ -70,6 +70,7 @@ typedef parsley_context * contextPtr;
void parsed_parsley_free(parsedParsleyPtr);
+void killDefaultNS(xmlDocPtr doc);
void parsley_free(parsleyPtr);
parsleyPtr parsley_compile(char* parsley, char* incl);
parsedParsleyPtr parsley_parse_file(parsleyPtr parsley, char* file, int flags);
View
1  test/default-namespace.json
@@ -0,0 +1 @@
+{ "path": " GuitarToolkit " }
View
3  test/default-namespace.let
@@ -0,0 +1,3 @@
+{
+ "path": "//iTunes"
+}
View
0  test/itunes.xml → test/default-namespace.xml
File renamed without changes
View
0  test/itunes.json
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.