2009-06-18 3 views
2

KML2.2 xml schema (VS2008 SDK의) XSD.exe 도구를 사용하여 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

XSD.EXE가 내 입찰을 수행 할 수 있도록 빠른 LinqPad 스크립트를 작성했습니다.이 파일을 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/

에서 그것에 대해 더 읽기