【问题标题】:Convert XDocument to xsd file through code [duplicate]通过代码将XDocument转换为xsd文件[重复]
【发布时间】:2012-10-23 20:12:12
【问题描述】:

可能重复:
How to create XSD file programmatically in C#?

我有一个 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); 

【问题讨论】:

    标签: c# xml xsd


    【解决方案1】:

    如果在XDocument对象中加载的XML符合XSD格式,只需将其保存在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 格式,那么您可以使用以下代码根据输入XML 生成XSD

    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);
    

    现在您可以在 C:\ 驱动器根目录中使用您的 XSD

    【讨论】:

    • 很明显,发布的文档不是XSD...
    猜你喜欢
    • 1970-01-01
    • 2011-10-04
    • 2015-12-05
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 2014-01-17
    相关资源
    最近更新 更多