如何在C#中使用XML [英] How to work with XML in C#
问题描述
任何人都有以下链接:如何在C#中使用XML?谢谢!
Anyone have a link for: How to work with XML in C#? Thanks!
推荐答案
查看此链接。
C#和XML源代码文档 [ ^ ]
首先你应该有一个看看MSDN:
LINQ to XML [ ^ ]
你可能会还想看看:
了解C# :简单的LINQ to XML [ ^ ]
LINQ to XML [ ^ ]
如果您要使用非常大的xml文件,可以在以下位置使用SAX实现: SAX for .NET [ ^ ]
祝你好运
Espen Harlinn
First of all you should have a look at MSDN:
LINQ to XML[^]
You will probably also like to have a look at:
Understanding C#: Simple LINQ to XML[^]
LINQ to XML[^]
If you''re going to work with really large xml files, there is a SAX implementation available at: SAX for .NET[^]
Best regards
Espen Harlinn
.NET中有不同的XML库。以下是简短概述:
There are different XML libraries in .NET. Here is a short overview:
- 使用
System.Xml.XmlDocument
class。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextWriter
和System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ ^ ], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
系统.Xml.Linq.XDocument
;这是类似于XmlDocument
的最合适的方式,支持LINQ to XML Programming。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ]。
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
andSystem.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
请注意,在许多情况下,您不需要直接使用XML。如果您使用序列化,可以为您完成。请参阅:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework [ ^ ],
http://msdn.microsoft.com/ en-us / library / vstudio / aa349369%28v = vs.90%29.aspx [ ^ ]。
最先进的一个同时,最容易使用的序列化基于数据合同。请参阅: http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ]。
请参阅我过去的答案,我提倡这种方法:
如何在表单应用程序中使用XML文件编写器和阅读器? [ ^ ],
创建属性文件...... [< a href =http://www.codeproject.com/Answers/176011/Creating-a-property-files#answer3target =_ blanktitle =New Window> ^ ]。
Note that in many cases you don''t need to work with XML directly. It can be done for you if you are using serialization. Please see:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework[^],
http://msdn.microsoft.com/en-us/library/vstudio/aa349369%28v=vs.90%29.aspx[^].
One of the most advanced and, at the same time, easiest to use serialization is based on Data Contract. Please see: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].
Please see also my past answer where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].
这篇关于如何在C#中使用XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!