I'm working with DTD in T-SQL and for the following code:
use customers;
DECLARE @xmlData XML;
SET @xmlData = '<!DOCTYPE replace [<!ENTITY example "Doe"> ]><customer><name>John Doe</name><address>123 Main St, Anytown, USA</address><salary>&example</salary></customer>';
INSERT INTO customers (name, address, salary)
SELECT
T.c.value('(name/text())[1]', 'NVARCHAR(MAX)'),
T.c.value('(address/text())[1]', 'NVARCHAR(MAX)'),
T.c.value('(salary/text())[1]', 'DECIMAL(18, 2)')
FROM @xmlData.nodes('/customers/customer') AS T(c);
I got the following error message.
Parsing XML with internal subset DTDs not allowed. Use
CONVERTwith style option 2 to enable limited internal subset DTD support.
I tried to fix the convert function:
SET @xmlData = CONVERT(XML, @xmlData, 2);
Select CONVERT(XML, @xmlData, 2);
And nothing seems to fix the issue. Can someone give me some hints?
Trying to
CONVERTthe variable after you've already failed to assign it won't work. You need to explicitlyCONVERTthe literal string you have:This, however, will give you a different error (and print statement):
This error is because of
<salary>&example</salary>; the ampersand needs to be escaped as&. If you fix that at your source, then it works and the DTD is stripped: