2009-06-18 38 views
2

我想使用XSD.exe工具(來自VS2008 SDK)從KML2.2 xml schema生成C#幫助文件。使用KML2.1,該工具工作得很好。但是,KML2.2架構包含指向other schemas的導入標記,導致XSD.exe發生異常。使用XSD.exe生成C#幫助類:處理導入的模式失敗

這是錯誤消息我得到:

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. 

你有建議,我怎麼能生成我的C#幫助文件?

回答

5

您必須在命令行中指定所有涉及的XSD(包括導入)。 Here's以博客文章爲例。

0

我寫了一個快速的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/