问题描述
在Visual Studio中,你可以创建一个从现有模式的模板XML文档。新 XML架构资源管理器在VS2008 SP1借此舞台进一步可以创建一个示例XML文档完成与数据。是否有一个类库在.NET中自动执行此操作,而不必使用Visual Studio?我发现MSDN上的 XmlSampleGenerator 的文章,但它是写于2004年,所以也许有一些已经列入在.NET现在做到这一点?
In Visual Studio you can create a template XML document from an existing schema. The new XML Schema Explorer in VS2008 SP1 takes this a stage further and can create a sample XML document complete with data.Is there a class library in .NET to do this automatically without having to use Visual Studio? I found the XmlSampleGenerator article on MSDN but it was written in 2004 so maybe there is something already included in .NET to do this now?
推荐答案
一些步法参与,但你可以加载XSD到DataSet对象,遍历表和每个调用调用NEWROW添加一些行()每个然后将这些行返回到它们各自的表..然后保存数据集到一个文件:
some footwork is involved, but you could load the xsd into a DataSet object, iterate over the Tables and add a few rows in each by calling calling NewRow() on each and then adding those rows back into their respective tables.. then save the DataSet out to a file:
DataSet ds = new DataSet();
ds.ReadXmlSchema("c:/xsdfile.xsd");
foreach(DataTable t in ds.Tables)
{
var row = t.NewRow();
t.Rows.Add(row);
}
ds.WriteXml("c:/example.xml");
P.S。一些额外的工作,而只是遍历每个表型和添加空行,你可以建立一个很好的WinForm的,它会让你在一些数据下降为每一行。我在几个星期前建于大约一个小时这样的事情。
P.S. A little extra work, but instead of just iterating over each table type and adding empty rows, you could build a nice winform that would allow you to drop in some data for each of the rows. I built something like this in about an hour a few weeks ago.
这篇关于是否有一个类来生成:在.NET XSD架构一个示例XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!