如何在vb.net中将String转换为XML [英] How do I convert a String into a XML in vb.net
问题描述
我有一个包含一行和一列的数据集。进入那个单元格已经保存了一个xml(在sql server中创建并将convertet转换为strinf)
我怎么能在vb中。将该字符串转换为xml?
I have a dataset with one row and one column. into that cell a have saved an xml ( created in sql server and convertet into a strinf)
How can I in vb. convert that string into an xml?
推荐答案
您可以使用.NET FCL提供的不同方法。以下是我对它们的简短概述:
You can use different approaches offered by .NET FCL. Here is my short overview of them:
- 使用
System.Xml.XmlDocument
类。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
System.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 class
System.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.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 /序列化 [ ^ ],
https://msdn.microsoft.com /en-us/library/7ay27kt9%28v=vs.110%29.aspx [ ^ ]。
特别是,您可以使用 DataContract : https://msdn.microsoft.com/ en-us / library / ms733127%28v = vs.110%29.aspx [ ^ ]。
Besides, not in all cases you have to work with XML directly. In many cases, you can use serialization
http://en.wikipedia.org/wiki/Serialization[^],
https://msdn.microsoft.com/en-us/library/7ay27kt9%28v=vs.110%29.aspx[^].
In particular, you could use DataContract: https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].
尝试 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument%28v=vs.110%29.aspx [ ^ ]。
这篇关于如何在vb.net中将String转换为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!