34

ファッショナブルであるという理由だけでXMLが使用されているように感じることもあります。

4

20 に答える 20

65

いくつかの強み:

  • XSDに対してXMLデータを検証できます
  • 文字通り説明することなく、XMLデータを作成/消費する必要がある他の関係者に(XSDとして)契約を簡単に提供できます。
  • XMLデータ表現のマルチレベルで1対多の関係を持つことができます
  • XMLはCSVよりも間違いなく読みやすいです
  • XMLは.netフレームワークによってネイティブにサポートされています

私の頭のてっぺんからいくつか例を挙げると。

于 2009-11-30T14:26:22.910 に答える
23

.csvファイルは、データが厳密に表形式であり、その構造がわかっている場合に適しています。データのさまざまなレベル間で関係を築き始めるとすぐに、ネストするだけで関係を(スキーマがなくても)明らかにできるため、xmlはより適切に機能する傾向があります。

于 2009-11-30T14:29:53.613 に答える
20

XML has become the default for its many benefits that lots of other people have already mentioned. So the question really becomes "When and Why is CSV preferable to XML?".

I feel CSV is preferable to XML when: - you are loading simple tabular data - you are in control of both the generation and consumption of the data file - the dataset is large

CSV is perfectly usable if the first 2 points are true, and has a performance benefit that becomes more significant the larger the dataset is.

I did a quick test loading ~8000 records each with 6 text fields. Loading and parsing the XML took ~8 seconds. Loading the CSV took less than 1 second.

The overhead of XML is worth it in a lot of cases, but when the stars align, CSV makes more sense.

于 2012-01-18T19:16:14.683 に答える
13

CSVは、ある情報に関連する一連の値があり、各フィールドの値を常に保存することがわかっている場合に役立ちます。

XMLには、自己記述型のデータ(タグ)と階層があるという利点があります。これにより、データの保存方法が大幅に柔軟になります。

于 2009-11-30T14:28:34.903 に答える
8

ネット上で興味深いパフォーマンステストを見つけました。XMLの機能が必要ない場合のXMLの欠点の神の例。

「スティーブンの実験を別の角度から試しました。ExcelXPスプレッドシートに1桁の数値を入力し、XMLとコンマ区切りテキストファイル(CSV)の両方で保存しました。次に、WinZipで両方を圧縮してから、両方を開きました。 Excelで。これが私が見つけたものです:

XMLファイルは840MB、CSV 34MB-2,500%の差圧縮、XMLファイルは2.5MB、CSV 0.00015MB(150KB)-1,670%の差でした。

同様に劇的なのは、ファイルをExcelスプレッドシートとして解凍してレンダリングするのにかかった時間です。XMLファイルでは約20分かかりました。CSVには1分かかりました。2,000%の違いです。」

http://www.xml.com/pub/a/2004/12/15/deviant.html

于 2012-01-19T07:59:44.117 に答える
7

XMLとCSVを使用すると、はるかに複雑な階層などと構造を持つことができます。それははるかに多くの柔軟性を提供します。

于 2009-11-30T14:28:01.667 に答える
5

XML is preferrable over CSV when the data is unstructured (unknown schema) and will be read by a human.

Arguably, unless the data contains predominantly text, CSV is also meant for human consumption.

Also relevant, is if your data is 2 or 3 dimensional. CSV is most suitable for 2 dimensional text, and due to its' verbosity, XML works well with 3 dimensional data.

The whole "standardness" of XML is hyperbole, and should not be taken literally. XML does have huge technical issues and many of the solutions aren't particularly elegant, or in many cases useful:

  1. It uses text to specify its own text-encoding (chicken and egg?)
  2. None of the more common schema languages for XML work particularly well.
  3. The ancient and commonplace way of creating mark-up languages using <tags> is not particularly helpful as a standard.
  4. XML tries to retroactively shoehorn more powerful mark-up languages such as the SGML based ones, into itself, creating a mess of incompatible legacy.
  5. It still remains to be determined whether or not XML text escape sequences can work for anything but the most simple cases (ie. friendly data).

To be clear, XML is probably the incorrect choice for 90% of the data interchange it is currently being used for, since those uses break some or all of the above assumptions.

于 2013-04-22T14:08:17.217 に答える
4

もちろん、それはファッショナブルで話題に値することもあります。それはすべてあなたのアプリケーションに依存します。解析が簡単なXMLの構成ファイルが好きです。一方、DataGridViewまたはデータベースダンプにはCSVファイルを使用します。

この毎日のWTF:XMLとCSVの選択は明らかですが、決定を下すのに役立ちます;)

于 2009-11-30T14:30:00.830 に答える
4

I have found of the greatest advantages of XML to be the parsing functionality and the strict validation that comes out-of-the-box with most XML libraries. The insistence on well-formedness and easy-to-understand error message (xyz not closed in line x, column y) are a real help compared to hunting broken values, or unknown behaviour, because of an error in the CSV file.

于 2009-11-30T15:22:27.017 に答える
3

In addition to the other answers, XML allows you to specify which character set the document is in.

于 2009-11-30T14:34:01.513 に答える
2

CSVは、通常XMLの2分の1であるため、物事を移動したい場合はより軽量です。

XMLは標準であり、異なるOSのバージョンのCSVに影響されることはありません

于 2009-11-30T14:28:44.967 に答える
2

I don't have enough reputation to comment on the relevant answer, but someone suggested compressing the XML as a way to gain size parity with csv formats. While this is true, XML compression can somtimes come back to bite you. If you are transferring XML data from point to point and it fails, it's nice to be able to read the XML and figure out what went wrong. If the XML is compressed and the transfer fails, it's sometimes not possible to decompress it and examine the contents. In other words compressing XML cancels out the human-readability advantage it has.

于 2009-11-30T15:15:12.970 に答える
2

I would say use XML (and or JSON) because someday you or someone (with a short temper and a large gun collection) may have to go find an error in the CSV data.

So yes, I'm saying readability, don't forget to think of the other guy! He may be thinking about you.

于 2009-11-30T16:27:34.087 に答える
1

XML provides a way of tagging your data with metadata (provided by the tag names and attribute names), whereas CSV does not. Couple this with the ability to define structured hierarchies and it makes XML easier to understand when provided with just the data, whereas CSV would require an accompanying tool or document to describe how each value is interpreted.

于 2009-11-30T14:35:58.577 に答える
1

You can easily traverse through XML data even when you have complex data.

Check these links:

于 2009-11-30T14:36:08.383 に答える
0

Structured, human readable, easier to edit, validation, parsability, transformability, typing, namespaces, powerful libraries behind it, are all amongst many of the reasons.

Above all else though it is standard.

于 2009-11-30T14:32:12.547 に答える
0

And again one more for XML: The X in XML stands for Extensible (I know, not really mnemonic :-P). That means, with the help of the XML namespace mechanism, you can join any two XML languages you like and combine them in the same document. Given that there is only one CSV 'language' (not counting the myriads of delimiter styles), XML can handle quite a lot of complexity, and that in a modular way.

This however, is the advantage of CSV: If you really have tabular data, XML syntax is most often overkill.

于 2009-11-30T14:39:27.710 に答える
0

I've also found that some cvs generators/parsers have a lot of difficulty with general text data. Long text strings with a lot of carriage returns and commas and quotations, etc etc, just make life really difficult when it comes to manipulating a cvs.

SSMS likes to truncate csv for fun.

于 2009-11-30T15:32:42.280 に答える
0
  1. There are existing parsers and emitters for it in every language and database
  2. They deal with encoding for me
  3. They deal with escaping for me

That's all that matters to me.

Sure, there's a semi-standard way to do escaping in CSV (i.e., "the way Excel does it"), and it's not exactly hard to write yourself, but it does take some time. And then you've got to implicitly agree on a character encoding out-of-band. But then, because it's so simple, people try to write it themselves, and invariably screw up either #2 or #3.

JSON also meets #2 and #3 and is getting close to satisfying #1. It's also arguably simpler, at least for non-document files. Not surprisingly, I find myself using it more and more, internally and externally.

于 2009-11-30T16:43:30.613 に答える
-2

そして、それがはるかに読みやすいので、私もそれを好みます。

于 2009-11-30T14:27:05.483 に答える