0

可能重复:
如何在 C# 中以编程方式创建 XSD 文件?

我有一个 XDocument 对象,我想通过代码将其转换为 xsd 文件

我该怎么做?

我的项目如下所示:

WebClient client = new WebClient(); 
Stream stream = client.OpenRead("http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&mode=bicycling&language=fr-FR&sensor=false"); 
XDocument doc = XDocument.Load(stream); 
4

1 回答 1

2

XSD如果加载XMLXDocument对象符合XSD格式,只需将其保存在扩展中。

WebClient client = new WebClient(); 
Stream stream = client.OpenRead("http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&mode=bicycling&language=fr-FR&sensor=false"); 
XDocument doc = XDocument.Load(stream);
// ...
doc.Save(@"C:\AnyFileName.xsd");

添加:或者如果XML不是XSD格式,那么您可以使用以下代码XSD根据输入生成:XML

doc.Save(@"C:\xmlFile.xml");
string parms = @"C:\File.xml /outputdir:C:\\";
string xsdExePath = @"C:\Program Files\...\xsd.exe";
ProcessStartInfo psi = new ProcessStartInfo(xsdExePath, parms);
var process = System.Diagnostics.Process.Start(psi);

现在,您可以XSD在 C:\ 驱动器根目录下使用。

于 2012-10-23T10:52:05.960 回答