question

xnl28 avatar image
xnl28 asked

Validate XML against DOCTYPE in T-SQL

Hello, I am importing an XML document within a stored procedure and need to validate it against the DOCTYPE definition included within the file. How can this be done? MSDN says that sp___xml_preparedocument will do this (see example B at [ http://msdn.microsoft.com/en-us/library/ms187367(v=sql.105).aspx][1]), but it allows invalid documents. For example, the code below gives no error or message, even thought the XML document is invalid becuase the required CustomerID attribute is missing. Does anyone know how perform the validation correctly? DECLARE @hdoc int DECLARE @doc varchar(2000) SET @doc = ' ]> ' EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc SELECT * FROM OPENXML (@hdoc, '/root/Customers',902384001) WITH (CustomerID varchar(10), ContactName varchar(20)) EXEC sp_xml_removedocument @hdoc [1]: http://msdn.microsoft.com/en-us/library/ms187367(v=sql.105).aspx
sql-server-2008-r2xml
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Kev Riley avatar image
Kev Riley answered
That's a good question. BOL certainly states that it validates it, but doesn't state how it returns any info. I've tried a number of variations and can't find the answer! A quick Google search shows that this has been asked in a few places, a number of times - all without resolution. Maybe you should raise this on [Connect][1] [1]: http://connect.microsoft.com/
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.