[英]XML parsing error: 'A string literal was expected' when inserting values into table
In Microsoft SQL Server 2008 I am attempting to insert values into an sql table with the columns type_id of datatype int and xml_info of datatype XML . 在Microsoft SQL Server 2008中,我试图将值插入数据类型为int的type_id和数据 类型为XML的xml_info的值的sql表中。 I am using the following query:
我正在使用以下查询:
INSERT INTO tbl_applied_devices ([type_id],[xml_info])
VALUES (1,'<Profile ID=99><Server><ID>BC4A18CA-AFB5-4268-BDA9-C990DAFE7783</ID> <Name>localhost</Name><Services></Services></Server></Profile>')
But I keep getting this error: 但我不断收到此错误:
Msg 9413, Level 16, State 1, Line 4
讯息9413,第16级,州1,第4行
XML parsing: line 1, character 13, A string literal was expectedXML解析:第1行,字符13,应为字符串文字
What am I doing incorrectly? 我做错了什么?
EDIT: I found that the source of the error is the xml element's ID attribute, <Profile ID=99>
seems to be what is causing the error. 编辑:我发现错误的根源是xml元素的ID属性,
<Profile ID=99>
似乎是导致错误的原因。 How can I correctly insert xml with an attribute ? 如何正确插入带有属性的xml? Do I need to somehow escape one of the characters?
我需要以某种方式逃脱其中一个角色吗?
XML documents are text ual by nature.
XML文档本质上是文本的。 This is not HTML for a web page, so you need ALL attribute values in quotes (single or double).
这不是网页的HTML,因此您需要在引号中包含所有属性值(单引号或双引号)。
INSERT INTO tbl_applied_devices ([type_id],[xml_info])
VALUES (1,'<Profile ID="99"><Server><ID>BC4A18CA-AFB5-4268-BDA9-C990DAFE7783</ID> <Name>localhost</Name><Services></Services></Server></Profile>')
It's very hard to parse the XML 1.0 specifications but here's a Microsoft version for .Net 4.5 , which is just as relevant for SQL Server XML. 解析XML 1.0规范非常困难,但这是.Net 4.5的Microsoft版本,与SQL Server XML同样重要。
Attributes, ID is an attribute, must be quoted. 属性(ID是属性)必须加引号。 Try ID="99"
尝试ID =“ 99”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.