Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: XPATH Query failing

I am working in SQL Server Management Studio on a stored procedure. There is a column containing XML that I am trying to access with XPATH but I get this error:

Parsing XML with internal subset DTDs not allowed. Use CONVERT with style option 2 to enable limited internal subset DTD support`

I read the docs on convert and importing xml but no luck.

To be clear, I have XML stored in a column in a table, and now want to access it with xpath after querying it into memory in a stored procedure. Anyone know what I should do?

like image 388
David Williams Avatar asked Apr 12 '13 22:04

David Williams


People also ask

What is XPath in SQL?

XPath is a graph navigation language used to select a set of nodes from an XML document. Each XPath operator selects a node-set based on a node-set selected by a previous XPath operator. For example, given a set of <Customer> nodes, XPath can select all <Order> nodes with the date attribute value of "7/14/1999".

How can show error message in stored procedure in SQL Server?

You can use the RAISERROR statement to generate your own errors in Transact-SQL code. You can also define your own error messages, starting with number 50001, using the system stored procedure sp_addmessage, which will add a message to the sysmessages table.


1 Answers

Your most likely getting this because somewhere inside of your XML you are using a document definition such as this: (MSDN example of DTD)

<!DOCTYPE DOC [<!ATTLIST elem1 attr1 CDATA "defVal1">]><elem1>January</elem1>

Microsoft blocks this by default as it creates a potential security hole. The convert with style option 2 message is telling you that you can enable partial support for DTD in order to process this XML through use of the CONVERT function as it relates to XML.

I don't have personal experience with doing that so I can't offer more than the link to MSDN.

The only other option is to enable full DTD support on the server which Microsoft does not recommend.

like image 196
RThomas Avatar answered Sep 27 '22 19:09

RThomas