以XML或SQL存储数据?

时间:2021-12-05 17:44:14

I'm developing a Windows Phone 7.5 app.

我正在开发一个Windows Phone 7.5应用程序。

I have to store 22 items with the following fields:

我必须存储以下字段的22个项目:

  1. Number (int).
  2. 数字(int)。
  3. Name (string).
  4. 名称(字符串)。
  5. Description (string).
  6. 描述(字符串)。

Name and description will be in various languages.

名称和描述将使用各种语言。

Now, I'm using a XML file like this:

现在,我正在使用这样的XML文件:

<?xml version="1.0" encoding="utf-8" ?>
<cards>
  <card id ="0" name="Mad" description="xxx" ></card>
...
</cards>

I haven't work with XML a lot, and I'm not sure which is the best way to do it.

我没有使用过很多XML,我不确定哪种方法最好。

Any advice? What do you recommend me? I need to store each name and description in different lanaguages.

任何建议?你有什么推荐我的?我需要将每个名称和描述存储在不同的语言中。

3 个解决方案

#1


3  

I would structure your xml as follows

我会按如下方式构建你的xml

 <cards>
   <card id ="0">
      <name lang="en">Mad</name>
      <description lang="en">xxx</description>
   </card>
   <card id ="1">
      <name lang="fr">Brother</name>
      <description lang="fr">xxx</description>
   </card>
   .... etc ....
 </cards>

By having it in this structure you only have 1 attribute per element and it is easy to find child elements which is the data you are looking for.

通过在此结构中使用它,每个元素只有1个属性,并且很容易找到子元素,这是您要查找的数据。

Actually there is another question that goes over this XML best practices: attributes vs additional elements

实际上,还有另一个问题涉及这个XML最佳实践:属性与其他元素

#2


0  

Reading your post and tags, I undestand you want to store this data in SQL SERVER. You can have a table with different languages, and the XML will have to contain atributes name and description according to this languages, as name_ES, name_EN, name_FR,... (the same for description).

阅读你的帖子和标签,我想你不想将这些数据存储在SQL SERVER中。您可以拥有一个包含不同语言的表,并且XML必须包含根据这些语言的属性名称和描述,如name_ES,name_EN,name_FR,...(描述相同)。

Then, programatically, you can have a DataSet object maping your SQL SERVER table. If I'm not wrong, there's the possibility to parse your XML to this DataSet object directly.

然后,以编程方式,您可以使用DataSet对象来编写SQL SERVER表。如果我没错,可以直接将XML解析为此DataSet对象。

#3


0  

If you only have a small number of items like this reading a whole XML file into memory is no problem, SQL does not give you much advantage. SQL comes into its own when you have large complicated databases and you need to be able to query it quickly and flexibly. If you have lots of data (to much to load into memory) and you need to selectively extract items from your database, XML is a pain (you need to parse it and implement the logic which will detect matches for your query), whereas SQL is designed for that, is lightning fast and queries can be arbitrarily complex (well, within reason).

如果您只有少量这样的项目将整个XML文件读入内存是没有问题的,那么SQL并没有给您带来太多好处。当您拥有大型复杂的数据库并且需要能够快速灵活地查询SQL时,SQL就会自成一体。如果您有大量数据(要加载到内存中),并且需要从数据库中有选择地提取项目,那么XML就很麻烦(您需要解析它并实现将检测查询匹配的逻辑),而SQL专为此而设计,快速闪电,查询可以任意复杂(在合理范围内)。

#1


3  

I would structure your xml as follows

我会按如下方式构建你的xml

 <cards>
   <card id ="0">
      <name lang="en">Mad</name>
      <description lang="en">xxx</description>
   </card>
   <card id ="1">
      <name lang="fr">Brother</name>
      <description lang="fr">xxx</description>
   </card>
   .... etc ....
 </cards>

By having it in this structure you only have 1 attribute per element and it is easy to find child elements which is the data you are looking for.

通过在此结构中使用它,每个元素只有1个属性,并且很容易找到子元素,这是您要查找的数据。

Actually there is another question that goes over this XML best practices: attributes vs additional elements

实际上,还有另一个问题涉及这个XML最佳实践:属性与其他元素

#2


0  

Reading your post and tags, I undestand you want to store this data in SQL SERVER. You can have a table with different languages, and the XML will have to contain atributes name and description according to this languages, as name_ES, name_EN, name_FR,... (the same for description).

阅读你的帖子和标签,我想你不想将这些数据存储在SQL SERVER中。您可以拥有一个包含不同语言的表,并且XML必须包含根据这些语言的属性名称和描述,如name_ES,name_EN,name_FR,...(描述相同)。

Then, programatically, you can have a DataSet object maping your SQL SERVER table. If I'm not wrong, there's the possibility to parse your XML to this DataSet object directly.

然后,以编程方式,您可以使用DataSet对象来编写SQL SERVER表。如果我没错,可以直接将XML解析为此DataSet对象。

#3


0  

If you only have a small number of items like this reading a whole XML file into memory is no problem, SQL does not give you much advantage. SQL comes into its own when you have large complicated databases and you need to be able to query it quickly and flexibly. If you have lots of data (to much to load into memory) and you need to selectively extract items from your database, XML is a pain (you need to parse it and implement the logic which will detect matches for your query), whereas SQL is designed for that, is lightning fast and queries can be arbitrarily complex (well, within reason).

如果您只有少量这样的项目将整个XML文件读入内存是没有问题的,那么SQL并没有给您带来太多好处。当您拥有大型复杂的数据库并且需要能够快速灵活地查询SQL时,SQL就会自成一体。如果您有大量数据(要加载到内存中),并且需要从数据库中有选择地提取项目,那么XML就很麻烦(您需要解析它并实现将检测查询匹配的逻辑),而SQL专为此而设计,快速闪电,查询可以任意复杂(在合理范围内)。