以编程方式创建XML文件从XSD [英] Programmatically Create XML File From XSD

查看:238
本文介绍了以编程方式创建XML文件从XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XSD文件,我想在运行时创建的基础上XSD的XML文件。 (我的问题是基本相同这一个,除了在.NET的世界,而不是Java的。)

I have an XSD file and I want to create an XML file at runtime based on the XSD. (My question is basically the same as this one, except in the .NET world, rather than for Java.)

我已经运行 XSD.EXE / C / L:VB MyTest.xsd ,但生成不能被实例化的一类,因为它嵌套类从来没有实例化。看来,生成的类仅用于XML反序列化,但我没有一个XML文件,从反序列化。

I have run xsd.exe /c /l:vb MyTest.xsd, but that generates a class that cannot be instantiated and used, as it has nested classes that are never instantiated. It appears that the generated class is only used for XML deserialization, but I don't have an XML file to deserialize from.

运行 XSD.EXE / D / L:VB MyTest.xsd 生成一个数据集,但它看起来像使用会更编码不仅仅是编写了一个的XmlDocument 手动。

Running xsd.exe /d /l:vb MyTest.xsd generates a dataset, but it looks like using that would be more coding than just writing out an XmlDocument manually.

什么是创建一个基于特定架构的XML文件的最佳方法是什么?

What is the best way to create an XML file based on a specific schema?

推荐答案

原来我只是被钝。虽然由XSD生成的类包含未初始化的嵌套类,它们通过公共财产暴露,因此没有任何实例化他们自己阻止我。

It turns out I was just being obtuse. While the classes generated by xsd contain uninitialized nested classes, they are exposed via public properties, so there is nothing stopping me from instantiating them myself.

类似如下:

ElementA.ElementB = New ElementB()
ElementA.ElementB.Name = "Jason"

这篇关于以编程方式创建XML文件从XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆