2012-04-11 8 views
2

xsdスキーマ内の別のアセンブリで定義された複合型を使用する必要があります。両方の.xsdスキーマは組み込みリソースとして定義されており、アセンブリでインポートするシートをリンクしようとしましたが、アセンブリの結果は必要ありません。異なるアセンブリで定義された複合型xsdスキーマにインクルード

xmlページの1つを検証する必要がある場合は、この関数を呼び出しますが、操作内でxmlスキーマセットをカスケードで追加することはできません。

public static XmlSchema GetDocumentSchema(this Document doc) 
{ 
    var actualType = doc.GetType(); 
    var stream = actualType.Assembly.GetManifestResourceStream(actualType.FullName); 

    if (stream == null) 
    { 
     throw new FileNotFoundException("Unable to load the embedded file [" + actualType.FullName + "]"); 
    } 

    var documentSchema = XmlSchema.Read(stream, null); 

    foreach (XmlSchemaExternal xmlInclude in documentSchema.Includes) 
    { 
     var includeStream = xmlInclude.SchemaLocation != "Operations.xsd" 
      ? actualType.Assembly.GetManifestResourceStream(xmlInclude.Id) 
      : typeof (Operations).Assembly.GetManifestResourceStream(xmlInclude.Id); 

     if (includeStream == null) 
     { 
      throw new FileNotFoundException("Unable to load the embedded include file [" + xmlInclude.Id + "]"); 
     } 

     xmlInclude.Schema = XmlSchema.Read(includeStream, null); 
    } 

    return documentSchema; 
} 

これがメインのスキーマです:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="ExampleSheet" 
     attributeFormDefault="unqualified" 
     elementFormDefault="qualified" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:include id="Operations" schemaLocation="Operations.xsd"/> 
    <xs:element name="ExampleSheet"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="Operations" type="Operations"/> 
    </xs:sequence> 
    <xs:attribute name="version" type="xs:string" use="required"/> 
    </xs:complexType> 
    </xs:element> 
</xs:schema>  

そして、このオペレーションのスキーマです:たとえば

<xs:schema id="Operations"  
    elementFormDefault="qualified" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> 
<xs:element name="Operations" type="Operations"/> 
    <xs:complexType name="Operations"> 
    <xs:choice minOccurs="1" maxOccurs="unbounded"> 
     <xs:element name="Insert" type="Insert"/> 
     <xs:element name="InsertUpdate" type="InsertUpdate"/> 
     <xs:element name="Update" type="Update"/> 
     <xs:element name="Delete" type="Delete"/> 
    </xs:choice> 
    <xs:attribute name="version" type="xs:string" use="required"/> 
    <xs:attribute name="store" type="xs:string" use="required"/> 
    <xs:attribute name="chain" type="xs:string" use="optional"/> 
    </xs:complexType> 
</xs:schema> 

、私は挿入とExampleSheetを持っている場合それを認識することはできません。 OperationsとInsertはIXmlSerializableを実装するクラスで、最初のものはカスタムXmlSchemaProviderを使用して内部型のスキーマセットを取得します。

何か間違っていますか? ExampleSheetがオペレーションのメンバーにアシストするにはどうすればよいですか? ExampleSheetはIXmlSerializableを実装する必要がありますので、必要に応じてリーダーとライターを構築できますが、スキーマはまだ有効でしょうか?

+0

あなたに従うのは難しいです:) - 単純に言えば、別のスキーマから1つのスキーマを参照したいですか? – NSGaga

+0

@NSGagaはい、別のアセンブリからです。私の貧しい人々の説明のために申し訳ありません:) –

+0

これは助けますかhttp://stackoverflow.com/questions/2357943/whats-the-difference-between-xsdinclude-and-xsdimport – NSGaga

答えて

2

XmlSchemaの代わりにXmlSchemaSetクラスを調べましたか?

私はXMLシリアライゼーションについて多くのことをしていないので、あなたの現在のアプリケーションに適合するかどうかは分かりませんが、3つの別々のタイプで定義されているタイプスキーマ。

完全なXmlSchemaSetオブジェクトは、各スキーマのすべてのタイプにアクセスできます。

+0

ありがとうございました:) XmlSchemaSetを繰り返し、それらの型を実際のスキーマに追加すると、GetDocumentSchema! –

関連する問題