使用 XSD 生成的类在 VB 中读取 XML 的示例

发布于 2024-10-15 12:07:59 字数 136 浏览 3 评论 0原文

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

I have generated a Visual Basic class by using the XSD.exe utility in Visual Studio. I was wondering if anyone had an example of how you process the data in Visual Basic. The examples on MSDN are pretty poor. Pointing me to example code, even in Csharp, would be fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ〆星空下的拥抱 2024-10-22 12:07:59

假设您有一个从 XSD 生成的类 MyClass,并且您有一个包含适合 MySample.xml 中该类的 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!
}

这有帮助吗?

Assuming you have a class MyClass that's been generated from your XSD, and you have a file with XML data that fits that class in MySample.xml, you'd do something like this (sorry, I'm not fluent in VB - this is 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!
}

Does that help??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文