data types FEATURE support for union types in data
diff --git a/src/xml.c b/src/xml.c
index b5af06f..95b0e64 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -249,7 +249,7 @@
     for (u = context->ns.count - 1; u + 1 > 0; --u) {
         ns = (struct lyxml_ns *)context->ns.objs[u];
         if (prefix && prefix_len) {
-            if (!strncmp(prefix, ns->prefix, prefix_len) && ns->prefix[prefix_len] == '\0') {
+            if (ns->prefix && !strncmp(prefix, ns->prefix, prefix_len) && ns->prefix[prefix_len] == '\0') {
                 return ns;
             }
         } else if (!ns->prefix) {