sql-serverxmlxsdxml-dml

SQL Server XML DML Undeclared prefix


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.


Solution

  • 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;