Question

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.

Was it helpful?

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;

OTHER TIPS

In the interest of sanity, even though its not directly related to your code, and because this is a top googled post for "undeclared prefix", also look for xsi:nil="true" in your xml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top