What is the best way to save XML data to SQL Server?

ⅰ亾dé卋堺 提交于 2019-12-04 02:56:14

SQL Server 2005 and up have a datatype called "XML" which you can store XML in - untyped or typed with a XSD schema.

You can basically fill columns of type XML from an XML literal string, so you can easily just use a normal INSERT statement and fill the XML contents into that field.

Marc

You can use the function OPENXML and stored procedure sp_xml_preparedocument to easily convert your XML into rowsets.

If you are using SQL Server 2008 (or 2005), it has an xml native datatype. You can associate an XSD schema with xml variables, and Insert directly into columns of type xml.

gbn

Yes, SQL Server 2005 and above can parse XML out of the box.

You use the nodes, value and query methods to break it down how you want, whether values or attributes

Some shameless plugging:

Xml data and Xml document could have different meaning. When xml type is good for data, it doesn't save formatting (white spaces removed), so in some cases (e.g. cofiguration files) the best option is nvarchar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!