Storing data in XML or SQL?

本秂侑毒 提交于 2019-12-10 17:14:24

问题


I'm developing a Windows Phone 7.5 app.

I have to store 22 items with the following fields:

  1. Number (int).
  2. Name (string).
  3. Description (string).

Name and description will be in various languages.

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

<?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.

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


回答1:


I would structure your xml as follows

 <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.

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




回答2:


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).

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.




回答3:


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).



来源:https://stackoverflow.com/questions/8357724/storing-data-in-xml-or-sql

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