1

我使用 Visual Studio 中的 XSD.exe 实用程序生成了一个 Visual Basic 类。我想知道是否有人有您如何在 Visual Basic 中处理数据的示例。MSDN 上的例子很差。将我指向示例代码,即使在 Csharp 中,也可以。

4

1 回答 1

0

假设你有一个MyClass从你的 XSD 生成的类,并且你有一个包含适合该类的 XML 数据的文件MySample.xml,你会做这样的事情(对不起,我不熟悉 VB - 这是 C#):

// create the XML serializer class, based on your MyClass definition
XmlSerializer ser = new XmlSerializer(typeof(MyClass));

// create filestream to open & read the existing XML file
FileStream fstm = new FileStream(@"C:\mysample.xml", FileMode.Open, FileAccess.Read);

// call deserialize
var result = ser.Deserialize(fstm);

// if result is not null, and of the right type - use it!
MyClass deserializedClass = (result as MyClass);
if(deserializedClass != null)
{
  // do whatever you want with your new class instance!
}

这有帮助吗??

于 2011-02-04T05:58:44.880 回答