diff --git a/parser.c b/parser.c
index 58369ae8..2bc714fe 100644
--- a/parser.c
+++ b/parser.c
@@ -9249,6 +9249,12 @@ next_attr:
nameHashValue = ctxt->attallocs[j] | 0x80000000;
if (nsIndex == NS_INDEX_EMPTY) {
+ /*
+ * Prefix with empty namespace means an undeclared
+ * prefix which was already reported above.
+ */
+ if (aprefix != NULL)
+ continue;
nsuri = NULL;
uriHashValue = URI_HASH_EMPTY;
} else if (nsIndex == NS_INDEX_XML) {
diff --git a/result/errors/ns-undeclared.xml b/result/errors/ns-undeclared.xml
new file mode 100644
index 00000000..4e8b91e5
--- /dev/null
+++ b/result/errors/ns-undeclared.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/result/errors/ns-undeclared.xml.ent b/result/errors/ns-undeclared.xml.ent
new file mode 100644
index 00000000..a19fbe7e
--- /dev/null
+++ b/result/errors/ns-undeclared.xml.ent
@@ -0,0 +1,3 @@
+./test/errors/ns-undeclared.xml:1: namespace error : Namespace prefix xLink for href on linearGradient is not defined
+
+ ^
diff --git a/result/errors/ns-undeclared.xml.err b/result/errors/ns-undeclared.xml.err
new file mode 100644
index 00000000..a19fbe7e
--- /dev/null
+++ b/result/errors/ns-undeclared.xml.err
@@ -0,0 +1,3 @@
+./test/errors/ns-undeclared.xml:1: namespace error : Namespace prefix xLink for href on linearGradient is not defined
+
+ ^
diff --git a/result/errors/ns-undeclared.xml.str b/result/errors/ns-undeclared.xml.str
new file mode 100644
index 00000000..a19fbe7e
--- /dev/null
+++ b/result/errors/ns-undeclared.xml.str
@@ -0,0 +1,3 @@
+./test/errors/ns-undeclared.xml:1: namespace error : Namespace prefix xLink for href on linearGradient is not defined
+
+ ^
diff --git a/test/errors/ns-undeclared.xml b/test/errors/ns-undeclared.xml
new file mode 100644
index 00000000..8c3ceaf3
--- /dev/null
+++ b/test/errors/ns-undeclared.xml
@@ -0,0 +1 @@
+