Qualcuno sa perché questo testo XML genera un errore di carattere di nome non valido in SQL Server 2008?Analisi XML: riga 1, carattere 23, carattere nome non valido
'<cs><c a="2" b="CITY & STATE TX" c="CITY & STATE TX"/></cs>'
Messaggio di eccezione è
Msg 9421, Level 16, State 1, Line 2
XML parsing: line 1, character 23, illegal name character
seguito è la query utilizzata per analizzare questo xml
DECLARE @CaptionsDescriptions XML = '<cs><c a="2" b="CITY & STATE TX" c="CITY & STATE TX"/></cs>'
DECLARE @DocHandle int
DECLARE @CaptionsDescriptionsTable TABLE
(
ID INT IDENTITY(1,1),
languageID INT,
Caption VARCHAR(50),
Description VARCHAR(2000)
)
EXEC sp_xml_preparedocument @DocHandle OUTPUT,@CaptionsDescriptions
INSERT INTO @CaptionsDescriptionsTable SELECT a,b,c
FROM OPENXML(@DocHandle,'cs/c')
WITH (
a int, -- language id
b varchar(50), -- caption
c varchar(2000) -- description
)
-- remove document handler
EXEC sp_xml_removedocument @DocHandle
Grazie.
L'errore ti dice esattamente dove il carattere non valido è. Inoltre, perché taggare con C#? – leppie
Un bell'esempio per mostrare perché le persone non dovrebbero formare manualmente xml. – I4V
Cosa succede se provi a trasmettere la stringa come SqlString? Converte automaticamente & a &? – Fandango68