使用 XSD.exe 生成 C# 帮助程序类:处理导入架构失败

发布于 2024-07-24 10:07:47 字数 1339 浏览 5 评论 0原文

我想从 KML2.2 xml 架构 使用 XSD.exe 工具(来自 VS2008 SDK)。 对于 KML2.1,该工具运行得很好。 但是,KML2.2 架构包含指向其他架构的导入标记导致 XSD.exe 崩溃。

这是我收到的错误消息:

C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Sample
s\Sdm> xsd.exe d:\temp\kml22.xsd /c /l:CS /n:Google.Kml22 /o:D:\temp\

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.

Schema validation warning: The 'http://www.w3.org/2005/Atom:author' element is
 not declared. Line 311, position 12.
Schema validation warning: The 'http://www.w3.org/2005/Atom:link' element is not
 declared. Line 312, position 12.
Schema validation warning: The 'urn:oasis:names:tc:ciq:xsdschema:xAL:2.0:Address
Details' element is not declared. Line 314, position 12.

Warning: Schema could not be validated. Class generation may fail or may produce
 incorrect results.

Error: Error generating classes for schema 'd:\temp\kml22'.
  - The element 'http://www.w3.org/2005/Atom:author' is missing.

Do you have suggest how Could I generated my C# helper files?

I would like to produce C# helper files from the KML2.2 xml schema using the XSD.exe tool (from VS2008 SDK). With KML2.1, the tool worked just fine. However, the KML2.2 schema contains import tags pointing to other schemas causing XSD.exe to freak out.

This is the error message I get:

C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Sample
s\Sdm> xsd.exe d:\temp\kml22.xsd /c /l:CS /n:Google.Kml22 /o:D:\temp\

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.

Schema validation warning: The 'http://www.w3.org/2005/Atom:author' element is
 not declared. Line 311, position 12.
Schema validation warning: The 'http://www.w3.org/2005/Atom:link' element is not
 declared. Line 312, position 12.
Schema validation warning: The 'urn:oasis:names:tc:ciq:xsdschema:xAL:2.0:Address
Details' element is not declared. Line 314, position 12.

Warning: Schema could not be validated. Class generation may fail or may produce
 incorrect results.

Error: Error generating classes for schema 'd:\temp\kml22'.
  - The element 'http://www.w3.org/2005/Atom:author' is missing.

Do you have suggestions how could I generate my C# helper files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

探春 2024-07-31 10:07:47

您必须在命令行中指定所有涉及的 XSD,包括导入。 这里一篇博客文章一个例子。

You have to specify all of the XSDs involved, including imports, in the command line. Here's a blog post with an example.

寂寞清仓 2024-07-31 10:07:47

我写了一个快速的 LinqPad 脚本来让 XSD.EXE 执行我的命令。将其复制/粘贴到 LinqPad 中,更改第三行以指向您的 XSD,按 F5,然后 TADA!

void Main()
{
    var file = @"C:\.... some.xsd";
    Do(file);
    files.Dump();

    ("xsd.exe \"" + string.Join("\" \"", files) + "\" /classes").Dump();
}

private void Do(string file)
{
    file = file.ToLower();

    var dir = Path.GetDirectoryName(file);
    var contents = File.ReadAllText(file);
    var regex = @"schemaLocation=""(.*?)""";

    if (files.Contains(file))
    {
        return;
    }

    files.Add(file);

    var toProcess = Regex.Matches(contents, regex).OfType<Match>().Select (m => m.Groups[1].Value).Select (m => 
    {
        if (Path.IsPathRooted(m))
        {
            return m;
        }
        else
        {
            return Path.GetFullPath(Path.Combine(dir, m));
        }
    }).Select (m => m.ToLower()).Where (m => !files.Contains(m)).ToList();

    foreach (var nested in toProcess)
    {
        Do(nested);
    }
}
private List<string> files = new List<string>();

欲了解更多相关信息,请访问 http://www .alexdresko.com/2015/10/08/xsd-exe-and-imports-a-solution/

I wrote a quick LinqPad script to make XSD.EXE do my bidding.. Copy/paste this into LinqPad, change the 3rd line to point to your XSD, press F5, and TADA!

void Main()
{
    var file = @"C:\.... some.xsd";
    Do(file);
    files.Dump();

    ("xsd.exe \"" + string.Join("\" \"", files) + "\" /classes").Dump();
}

private void Do(string file)
{
    file = file.ToLower();

    var dir = Path.GetDirectoryName(file);
    var contents = File.ReadAllText(file);
    var regex = @"schemaLocation=""(.*?)""";

    if (files.Contains(file))
    {
        return;
    }

    files.Add(file);

    var toProcess = Regex.Matches(contents, regex).OfType<Match>().Select (m => m.Groups[1].Value).Select (m => 
    {
        if (Path.IsPathRooted(m))
        {
            return m;
        }
        else
        {
            return Path.GetFullPath(Path.Combine(dir, m));
        }
    }).Select (m => m.ToLower()).Where (m => !files.Contains(m)).ToList();

    foreach (var nested in toProcess)
    {
        Do(nested);
    }
}
private List<string> files = new List<string>();

Read more about it at http://www.alexdresko.com/2015/10/08/xsd-exe-and-imports-a-solution/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文