简体   繁体   English

使用XML DTD作为模板在C#中生成XML

[英]Use XML DTD as template to generate XML in C#

Only XML DTD is provided. 仅提供XML DTD。 How do I create XML from a giving class? 如何从给定类创建XML?

For simple DTD, I can use regular expression to extract the fields and populate a XML. 对于简单的DTD,我可以使用正则表达式提取字段并填充XML。 But is there a systematic way? 但是,有系统的方法吗?

You can create a xsd schema from your DTD using visual studio. 您可以使用Visual Studio从DTD创建xsd模式。 Open the DTD in visual studio and look for the 'create schema' function. 在Visual Studio中打开DTD,然后查找“创建模式”功能。 Then from there, you can use the xsd.exe command line utility to generate your class >> xsd YourSchema.xsd /c. 然后从那里,您可以使用xsd.exe命令行实用程序生成类>> xsd YourSchema.xsd / c。 With your newly generated class, you can use a XmlSerializer to serialize the object into XML. 使用新生成的类,可以使用XmlSerializer将对象序列化为XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM