有人知道为什么这个 XML 文本会在 SQL Server 2008 中引发非法名称字符错误吗?
'<cs><c a="2" b="CITY & STATE TX" c="CITY & STATE TX"/></cs>'
异常消息是
Msg 9421, Level 16, State 1, Line 2
XML parsing: line 1, character 23, illegal name character
以下是用于解析此 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