[英]Generating C# helper classes with XSD.exe: Failed handling imported schemas
I would like to produce C# helper files from the KML2.2 xml schema using the XSD.exe tool (from VS2008 SDK). 我想使用XSD.exe工具(来自VS2008 SDK)从KML2.2 xml模式生成C#帮助文件。 With KML2.1, the tool worked just fine.
使用KML2.1,该工具可以正常工作。 However, the KML2.2 schema contains import tags pointing to other schemas causing XSD.exe to freak out.
但是,KML2.2架构包含指向其他架构的导入标签,从而导致XSD.exe异常。
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? 您有建议如何生成C#帮助文件?
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! 我写了一个快速的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>();
Read more about it at http://www.alexdresko.com/2015/10/08/xsd-exe-and-imports-a-solution/ 请访问http://www.alexdresko.com/2015/10/08/xsd-exe-and-imports-a-solution/了解更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.