0

私は検索して検索しましたが、遠隔的に回答に似ているものは見つかりませんでした。dtdやxsdやxmlドキュメントからのNHibernateマッピング

私は、XMLドキュメントタイプ(私のドキュメントタイプ、NHibernate関連なし)のDTD(xml-dtd)を持っており、その特定のドキュメントタイプのすべてのドキュメントをリレーショナルモデルに保存したいと思います。いいえ、XMLファイル自体をvarcharやXMLなどのフィールドや目的に反してデータベースに格納したくないのですが、その代わりにその要素と属性に分解して保存する必要があります。適切な関係モデルとして。 XMLはこれをサポートしています。

ビジュアルスタジオ2015で、指定されたDTDからXSDを作成し、そのXSDを使用して、指定されたXSD(および元のDTDを拡張)を反映するC#クラスを作成できます。ドキュメントが解析され、すべてがOKです。

ここで問題は、これらのXML文書をNHibernateを介してRDBMSに格納する方法です(すべての関係がそのように存在する)。自動マッピング機能を使用することで簡単な方法が必要ですが、元のDTD(IDREFのものやそのようなリレーショナルなもの)には「制限」があります。文字列型の値として「コード」を格納するのではなく、他のクラスとの関係

だから基本的に、私は、これは容易に達成することができる方法についていくつかの光を当てるために、同時にNHibernateの& & XML & & DTD & & XSDの第一人者が必要です。私はこの種のものが少なくとも過去10〜15年間、hibernateとnhibernateで "正常"であったことを100%確信していました(私は決して試みたことがなく、データベースにXML文書を格納する必要があるのは初めてです全体としてではなく構成要素のビットへ)。

このようなことができない場合は、NHibernateのための "XMLドキュメントドライバ"のようなものがありますので、RDBMSに入る必要はありませんが、ファイルシステム上にXMLドキュメントとして残りますか?

例IDREFとNMTOKENのSGML/XMLの看護師のために、なぜ「ちょうど」の文字列であり、どこに行かなければならないのか、つまり別のクラスや用法、バリアントなどとの適切な関係はありません。 最終結果:値「G117と単なる文字列「コード」:私はリファレンスpublic virtual Class Reference { get; set; }

実際の結果のように、「コード」(またはID)G117自体(と「クラス」であることを期待する

"と同様に

[System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")] 
    public string code { 
     get { 
      return this.codeField; 
     } 
     set { 
      this.codeField = value; 
     } 
    } 

XMLファイル:

<Class code="G117" kind="process"> 
    <SuperClass code="G"/> 
    <Rubric id="13-223" kind="preferred"> 
     <Label xml:lang="en">A preferred label</Label> 
    </Rubric> 
    <Rubric id="13-224" kind="shortTitle"> 
     <Label xml:lang="en">Short title</Label> 
    </Rubric> 
    <Rubric id="13-225" kind="exclusion"> 
     <Label xml:lang="en">There is some exclusion text with a reference here <Reference>G12</Reference></Label> 
    </Rubric> 
    <Rubric id="13-226" kind="criteria"> 
     <Label xml:lang="en">Some criteria text goes here</Label> 
    </Rubric> 
</Class> 

<Rubric id="56-327" kind="exclusion"> 
    <Label xml:lang="en">This is some thext that might refer someplace <Reference>G117</Reference>; and another piece of text that refers to another place <Reference>BF9</Reference>; Another text describing something and there might be a reference from this piece of text somewhere else too <Reference>AB7</Reference></Label> 
</Rubric> 

はDTD:XSD結果の

<!ELEMENT Class (Meta*,SuperClass*,SubClass*,ModifiedBy*,ExcludeModifier*,Rubric*,History*)> 
<!ATTLIST Class code NMTOKEN #REQUIRED kind IDREF #REQUIRED usage IDREF #IMPLIED variants IDREFS #IMPLIED> 
<!ELEMENT Rubric (Label+,History*)> 
<!ATTLIST Rubric id ID #IMPLIED kind IDREF #REQUIRED usage IDREF #IMPLIED> 
<!ELEMENT Reference (#PCDATA)> 
<!ATTLIST Reference classCode CDATA #IMPLIED authority NMTOKEN #IMPLIED uid NMTOKEN #IMPLIED code NMTOKEN #IMPLIED usage IDREF #IMPLIED variants IDREFS #IMPLIED> 

<xs:element name="Class"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="Meta" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="SuperClass" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="SubClass" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="ModifiedBy" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="ExcludeModifier" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="Rubric" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="History" /> 
     </xs:sequence> 
     <xs:attribute name="code" type="xs:NMTOKEN" use="required" /> 
     <xs:attribute name="kind" type="xs:IDREF" use="required" /> 
     <xs:attribute name="usage" type="xs:IDREF" /> 
     <xs:attribute name="variants" type="xs:IDREFS" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Rubric"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element minOccurs="1" maxOccurs="unbounded" ref="Label" /> 
     <xs:element minOccurs="0" maxOccurs="unbounded" ref="History" /> 
     </xs:sequence> 
     <xs:attribute name="id" type="xs:ID" /> 
     <xs:attribute name="kind" type="xs:IDREF" use="required" /> 
     <xs:attribute name="usage" type="xs:IDREF" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Reference"> 
    <xs:complexType> 
     <xs:simpleContent> 
     <xs:extension base="xs:string"> 
      <xs:attribute name="classCode" type="xs:string" /> 
      <xs:attribute name="authority" type="xs:NMTOKEN" /> 
      <xs:attribute name="uid" type="xs:NMTOKEN" /> 
      <xs:attribute name="code" type="xs:NMTOKEN" /> 
      <xs:attribute name="usage" type="xs:IDREF" /> 
      <xs:attribute name="variants" type="xs:IDREFS" /> 
     </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
    </xs:element> 

生成されたC#クラス

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/MyStuff")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/MyStuff", IsNullable=false)] 
public partial class Class { 

    private Meta[] metaField; 

    private SuperClass[] superClassField; 

    private SubClass[] subClassField; 

    private ModifiedBy[] modifiedByField; 

    private ExcludeModifier[] excludeModifierField; 

    private Rubric[] rubricField; 

    private History[] historyField; 

    private string codeField; 

    private string kindField; 

    private string usageField; 

    private string variantsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Meta")] 
    public Meta[] Meta { 
     get { 
      return this.metaField; 
     } 
     set { 
      this.metaField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("SuperClass")] 
    public SuperClass[] SuperClass { 
     get { 
      return this.superClassField; 
     } 
     set { 
      this.superClassField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("SubClass")] 
    public SubClass[] SubClass { 
     get { 
      return this.subClassField; 
     } 
     set { 
      this.subClassField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("ModifiedBy")] 
    public ModifiedBy[] ModifiedBy { 
     get { 
      return this.modifiedByField; 
     } 
     set { 
      this.modifiedByField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("ExcludeModifier")] 
    public ExcludeModifier[] ExcludeModifier { 
     get { 
      return this.excludeModifierField; 
     } 
     set { 
      this.excludeModifierField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Rubric")] 
    public Rubric[] Rubric { 
     get { 
      return this.rubricField; 
     } 
     set { 
      this.rubricField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("History")] 
    public History[] History { 
     get { 
      return this.historyField; 
     } 
     set { 
      this.historyField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")] 
    public string code { 
     get { 
      return this.codeField; 
     } 
     set { 
      this.codeField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREF")] 
    public string kind { 
     get { 
      return this.kindField; 
     } 
     set { 
      this.kindField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREF")] 
    public string usage { 
     get { 
      return this.usageField; 
     } 
     set { 
      this.usageField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREFS")] 
    public string variants { 
     get { 
      return this.variantsField; 
     } 
     set { 
      this.variantsField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/MyStuff")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/MyStuff", IsNullable=false)] 
public partial class Rubric { 

    private Label[] labelField; 

    private History[] historyField; 

    private string idField; 

    private string kindField; 

    private string usageField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Label")] 
    public Label[] Label { 
     get { 
      return this.labelField; 
     } 
     set { 
      this.labelField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("History")] 
    public History[] History { 
     get { 
      return this.historyField; 
     } 
     set { 
      this.historyField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="ID")] 
    public string id { 
     get { 
      return this.idField; 
     } 
     set { 
      this.idField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREF")] 
    public string kind { 
     get { 
      return this.kindField; 
     } 
     set { 
      this.kindField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREF")] 
    public string usage { 
     get { 
      return this.usageField; 
     } 
     set { 
      this.usageField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/MyStuff")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/MyStuff", IsNullable=false)] 
public partial class Reference { 

    private string classCodeField; 

    private string authorityField; 

    private string uidField; 

    private string codeField; 

    private string usageField; 

    private string variantsField; 

    private string valueField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string classCode { 
     get { 
      return this.classCodeField; 
     } 
     set { 
      this.classCodeField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")] 
    public string authority { 
     get { 
      return this.authorityField; 
     } 
     set { 
      this.authorityField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")] 
    public string uid { 
     get { 
      return this.uidField; 
     } 
     set { 
      this.uidField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")] 
    public string code { 
     get { 
      return this.codeField; 
     } 
     set { 
      this.codeField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREF")] 
    public string usage { 
     get { 
      return this.usageField; 
     } 
     set { 
      this.usageField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="IDREFS")] 
    public string variants { 
     get { 
      return this.variantsField; 
     } 
     set { 
      this.variantsField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlTextAttribute()] 
    public string Value { 
     get { 
      return this.valueField; 
     } 
     set { 
      this.valueField = value; 
     } 
    } 
} 

答えて

0

このようなことに興味があるオスカーなど、私には12日かかりましたが、結局私はそれを理解して動作させました。マッピング、データベースを作成してxmlからデータを入力するのに数秒(多分2秒)かかりますが、それは美しく動作します。 「IDREF」タイプを実際のIDにマップする方法はまだわかりませんが、これは過去数日間行っていたものと比べて軽微な問題です。

0

を私は混乱している - あなたが矛盾しているようですあなた自身。ある時点で、「これらのXML文書をHibernate経由でRDBMSに格納する方法は?「その後、ちょっと後で聞いてみると「RDBMSに入る必要はなく、ファイルシステム上にXMLドキュメントとして残るように、NHibernate用の「XMLドキュメントドライバ」などのことさえありますか?」

どんな場合でも - NHibernateは、オブジェクトモデルとSQLを使用して照会できるさまざまなリレーショナルデータベースシステム間のマッピングのためのフレームワークです。XMLファイルを使用してデータを格納して公開するRDBMSこれらのファイルのSQLファサードはおそらくNHibernateドライバを書くことができますが、NHibernate自体にはXMLファイルをターゲットとするクエリエンジンのようなものは含まれていません。最善の策は、 NHibernateのマッピング設定。 NHibernateのXML設定に変換するか、Mapping-By-CodeまたはFluentNHibernateのコードを発行します。

+0

「このようなことができない場合は···」 – pele

+0

編集して追加しました「このようなことができない場合は、」と編集の承認をお願いいたします。 – pele

関連する問題