Posted by: Vijay Modi | July 2, 2008

MS SQl + XML parsing error: Reference to undeclared namespace prefix

When a namespace is declared in your xml document / String and you will use the OpenXml in your stored Procedure / Sql Query, you will get this type of error. To remove this error you need to define the namespace while you write the EXECUTE statement in you query/stored procedure.

Suppose you have written the following statement:

EXEC sp_xml_preparedocument @docHandle OUTPUT, @XmlDoc

So you need to change it with the following one:

EXEC sp_xml_preparedocument @docHandle OUTPUT, @XmlDoc, ‘<root xmlns:ns0=”http://vijaymodi.wordpress.com” />’

Where ns0 is the namespace of your xmlDocument, which is defined in the first node of your xml document. Suppose my xml document is as follows:

<ns0:root xmlns:ns0=”http://vijaymodi.wordpress.com”>
<ID>ID_0</ID>
<NAME>Name_0</NAME>
<Address>Address_0</Address>
<City>City_0</City>
</ns0:root>

Let me know if you have any query:)

Cheers,
Vijay Modi

Responses

Can u put some Interesting Topic in .Net, Not every time put Error which u faced,

Hi Jigar,

Right now I am working on Biztalk. And on net I am not finding such solutions. And I resolved some errors my own. So I think to keep it on Net as others time donot waste. I will write some interesting topic soon. Sorry for such type of articles. Currently I am busy, once I will get some time, I will write good article on .net too.

Regards,
Vijay Modi

I agreed with you

Leave a response

Your response:

Categories