SQL Server XML DML Undeclared prefix

Oscar picture Oscar · Aug 27, 2013 · Viewed 8.4k times · Source

I can't understand why I get the error "XML parsing: line 2, character 45, undeclared prefix" in this simple line of code:

DECLARE @ECAS XML;
SET @ECAS = 'declare namespace xs="http://www.w3.org/2001/XMLSchema";
             <xs:element name="ecasData">
               <xs:complexType>
                 <xs:all minOccurs="1" maxOccurs="1"/>
               </xs:complexType>
             </xs:element>';

SELECT @ECAS;

Isn't declared the namespace xs in the begin of the sentence? Any help will be appreciated. Thanks.

Answer

podiluska picture podiluska · Aug 27, 2013
DECLARE @ECAS XML;

SET @ECAS = '<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="ecasData" >
               <xs:complexType>
                 <xs:all minOccurs="1" maxOccurs="1"/>
               </xs:complexType>
             </xs:element>';
SELECT @ECAS;