Sidebar

XML Namespace has not been declared. What is a Namespace and how can this error be fixed?

0 votes
4.2K views
asked Mar 7, 2014 by gary-t-8719 (14,860 points)
edited Mar 7, 2014 by gary-t-8719

While working in QIE I often get a similar error referenceing a namespace problem like:
 

Namespace for prefix 'env' has not been declared.

1 Answer

0 votes

This is the description of XML namespaces taken from wikipedia

XML namespaces are used for providing uniquely named elements and attributes in an XML document

In this example, there is an xml namespace on line 2 for "http://www.w3.org/2003/05/soap-envelope", which defines the elements that should belong in a soap envelope.  This namespace is given an alias of "soapenv" by adding a :soapenv after the xmlns attribute name as seen here:

xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"

This allows the current or any nested elements to reference the declared namespace.  Here is the example on line 3 of a nested element referencing the soapenv namespace for the Header element:

<soapenv:Header>

If a namespace is declared, but is not given an alias, it is called the default namespace, and will remain the default namespace for all elements which do not explicitly reference another namespace.

Now onto to fixing the error.  The error states: "Namespace for prefix 'env' has not been declared."  Sure enough, env is not a declared alias for a namespace, but soapenv is.  This is a common mistake when copying an xml snippet from another example because the xmlns alias may be different.  So, to fix the error, use the xmlns alias that is declared for your xml document.  Change this:

env:relay="true"

To this:

soapenv:relay="true"

 

answered Mar 7, 2014 by mike-r-7535 (13,830 points)
...