I know the "XML parsing: semicolon expected" error is a data error, and not a SQL error. The first error I am trying to get rid of is the one about DTD subsets, so I am using CONVERT(xml, xml_data, 2), but then I get this: Msg 9411, Level 16, State 1, Line 14 XML parsing: line 1, character 94, semicolon expected
I don't have access to modify the actual xml. I am querying. It is data in a table (with >1 million records, so I don't even know which record is throwing the error), received from a vendor as responses to API calls. I am trying to shred the xml in a stored procedure, in order to extract bits of data. Is it possible to somehow bypass the records with the bad data? I am NOT processing row by row at the moment, nor do I want to.
Thanks!
I tried this, but it didn't work, either:
SELECT s.id as SessionID
, st.iD as TransmissionID
, st.TransmissionTypeID
, st.xml_data
, CONVERT(xml, replace(cast(st.xml_data as varchar(max)),'&','&'), 2) as converted_xml
, s.insertdt
, st.responsecode
INTO #Session_transmissions
FROM XML_Sessions s with (nolock)
join XML_Session_Transmissions st with (nolock) on s.id = st.tbl_Subscription_XML_SessionID
WHERE s.insertdt >= '3/1/2018`
This is what finally worked:
SELECT PrimaryKeyColumn, TRY_CONVERT(xml, VarcharColumn) AS XMLValue, VarcharColumn
FROM YourTable WHERE TRY_CONVERT(xml, VarcharColumn) IS NULL AND VarcharColumn IS NOT NULL;