Skip to content

Commit 4a762e2

Browse files
author
Kyle Maxwell
committed
default namespaces now work
1 parent f1e2716 commit 4a762e2

File tree

8 files changed

+46
-0
lines changed

8 files changed

+46
-0
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ check-am:
6262
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
6363
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."
6464
@echo "div..."; ./parsley test/div.let test/div.html 2>&1 | diff test/div.json - && echo " success."
65+
@echo "default-namespace..."; ./parsley -x test/default-namespace.let test/default-namespace.xml 2>&1 | diff test/default-namespace.json - && echo " success."

Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ check-am:
761761
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
762762
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."
763763
@echo "div..."; ./parsley test/div.let test/div.html 2>&1 | diff test/div.json - && echo " success."
764+
@echo "default-namespace..."; ./parsley -x test/default-namespace.let test/default-namespace.xml 2>&1 | diff test/default-namespace.json - && echo " success."
764765
# Tell versions [3.59,3.63) of GNU make to not export all variables.
765766
# Otherwise a system limit (for SysV at least) may be exceeded.
766767
.NOEXPORT:

parsley.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,47 @@ parsleyXsltError(void * ctx, const char * msg, ...) {
400400
va_end(ap);
401401
}
402402

403+
static bool
404+
hasDefaultNS(xmlDocPtr doc) {
405+
return xmlSearchNs(doc, doc->children, NULL) != NULL;
406+
}
407+
408+
static void
409+
_killDefaultNS(xmlNodePtr node) {
410+
if(node == NULL) return;
411+
412+
xmlNsPtr ns = node->nsDef;
413+
if(ns != NULL) {
414+
if(ns->prefix == NULL) node->nsDef = ns->next;
415+
xmlNsPtr prev = ns;
416+
while(ns = ns->next) {
417+
if(ns->prefix == NULL) prev->next = ns->next;
418+
}
419+
}
420+
421+
ns = node->ns;
422+
if(ns != NULL) {
423+
if(ns->prefix == NULL) node->ns = ns->next;
424+
xmlNsPtr prev = ns;
425+
while(ns = ns->next) {
426+
if(ns->prefix == NULL) prev->next = ns->next;
427+
}
428+
}
429+
430+
_killDefaultNS(node->children);
431+
_killDefaultNS(node->next);
432+
}
433+
434+
void
435+
killDefaultNS(xmlDocPtr doc) {
436+
if(hasDefaultNS(doc)) {
437+
_killDefaultNS(doc->children);
438+
}
439+
}
403440

404441
parsedParsleyPtr parsley_parse_doc(parsleyPtr parsley, xmlDocPtr doc, int flags) {
442+
killDefaultNS(doc);
443+
405444
parsedParsleyPtr ptr = (parsedParsleyPtr) calloc(sizeof(parsed_parsley), 1);
406445
ptr->error = NULL;
407446
ptr->parsley = parsley;

parsley.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ typedef parsley_context * contextPtr;
7070

7171
void parsed_parsley_free(parsedParsleyPtr);
7272

73+
void killDefaultNS(xmlDocPtr doc);
7374
void parsley_free(parsleyPtr);
7475
parsleyPtr parsley_compile(char* parsley, char* incl);
7576
parsedParsleyPtr parsley_parse_file(parsleyPtr parsley, char* file, int flags);

test/default-namespace.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "path": " GuitarToolkit " }

test/default-namespace.let

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"path": "//iTunes"
3+
}

test/itunes.json

Whitespace-only changes.

0 commit comments

Comments
 (0)