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 . 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
XML parsing: line 1, character 13, A string literal was expected
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. How can I correctly insert xml with an attribute ? Do I need to somehow escape one of the characters?
XML documents are ual by nature. 的。 This is not HTML for a web page, so you need ALL attribute values in quotes (single or double).
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.
Attributes, ID is an attribute, must be quoted. Try ID="99"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.