保存XML直接用C#数据库 [英] Save XML directly to Database with C#

查看:334
本文介绍了保存XML直接用C#数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的XML文件的一部分

Here is a part of my xml file

<teams>
  <team-profile>
    <name>Australia</name>
    <id>1</id>
    <stats type="Test">
      <span>1877-2010</span>
      <matches>721</matches>
      <won>339</won>
      <lost>186</lost>
      <tied>2</tied>
      <draw>194</draw>
      <percentage>47.01</percentage>
    </stats>
    <squad>
      <player id="135" fullname="Shane Warne"/>
      <player id="136" fullname="Damien Martyn"/>
      <player id="138" fullname="Michael Clarke"/>
    </squad>
  </team-profile>
</team>

我读的地方,有一个方法可以直接保存此XML数据库。我使用VS2010。我创建了数据集,因为我从这个XML所需要的数据。有什么办法来此XML直接在地图数据?
任何其他的想法?
我也有节省一些其他更复杂的XML文件到数据库中。

I have read somewhere that there is a way to save this XML directly to database. I am using VS2010. I have created the dataset, for the data i need from this xml. Is there any way to map this XML directly on dataset? Any other idea? I also have to save some other more complex XML files to database.

我曾尝试XSD.EXE创建此XML XSD架构。

I have tried xsd.exe to create xsd schema for this XML.

推荐答案

SQL Server的2005+具有原生XML数据类型,如果您创建一个列,你可以简单地做一个插入到该列,这里是一个插入类似你,这个表的第二列的数据类型是XML

SQL Server 2005+ has a native XML datatype, if you create a column, you can simply do an insert into that column, here is an insert similar to yours, this table's second column's datatype is xml

INSERT INTO docs VALUES (1, '<book genre="security"
publicationdate="2002" ISBN="0-7356-1588-2">
   <title>Writing Secure Code</title>
   <author>
      <first-name>Michael</first-name>
      <last-name>Howard</last-name>
   </author>
   <author>
      <first-name>David</first-name>
      <last-name>LeBlanc</last-name>
   </author>
   <price>39.99</price>
</book>')
INSERT INTO docs VALUES (2, 
'<doc id="123">
    <sections>
   <section num="1"><title>XML Schema</title></section>
   <section num="3"><title>Benefits</title></section>
   <section num="4"><title>Features</title></section>
    </sections>
</doc>')

这篇关于保存XML直接用C#数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆