2017-02-15 13 views
1

私はXSDファイルを持っています。 SQLからデータを取得し、データをデータセットに入力します。 注:SQLから1000レコードが得られます。SQLから既存のXSDファイル(複合)からXMLを生成

私はこれを作りたいと思います。 xsd形式のXMLファイルを生成する。ここで

は私のXSDです:

<xs:element name = 'automation'> 
    <xs:complexType> 
    <xs:sequence> 
      <xs:element name = 'auto' type = 'AutoType' minOccurs = '1' maxOccurs = 'unbounded' /> 
    </xs:sequence> 
    </xs:complexType> 

<xs:complexType name = "AutoType"> 
    <xs:sequence> 
    <xs:element name = "autoKodu" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> <!-- v --> 
    <xs:element name = "autoAdres" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> <!-- v --> 
    <xs:element name = 'bill' type = 'BillType' minOccurs = '1' maxOccurs = 'unbounded' /> 
    </xs:sequence> 

<xs:complexType name = "BillType"> 
    <xs:sequence> 
    <xs:element name = "dateOne" type = "xs:date" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "dateTwo" type = "xs:time" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = 'point' type = 'PointType' minOccurs = '1' maxOccurs = 'unbounded' /> 

    </xs:sequence> 

<xs:complexType name = "PointType"> 
    <xs:sequence> 
     <xs:element name = "plate" minOccurs = '1' maxOccurs = '1' > <!-- v --> 
    <xs:simpleType> 
     <xs:restriction base="xs:string"> 
      <xs:pattern value="([a-zA-Z0-9])*"/> 
     </xs:restriction> 
     </xs:simpleType> 
     </xs:element> 
    <xs:element name = "aa" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "bb" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "cc" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "dd" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "ee" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "ff" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "gg" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    <xs:element name = "hh" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' /> 
    </xs:sequence> 

xsd.exeを使用してxsdクラスを作成しました ソリューションに追加しました。

xsd.exe /c automation.xsd (the XSD file you have) 

プロジェクト(例えばAutomation.cs)にそのクラスファイルを追加します。あなたのVisual Studioコマンドプロンプトから

var data = new myClassOrSmthng? { ??? I do not know how to get datas from dataset here. } 

XmlSerializer serializer = new XmlSerializer(typeof(myClassOrSmthng)); 
       using (var stream = new StreamWriter(myPath)) serializer.Serialize(stream, data); 

答えて

0

は、クラスファイルを作成するには、次のコマンドを実行します。

その後、あなたはそのクラスを使用してXMLをシリアル化することができます:あなたの迅速な応答を

StringReader objStringReader = new StringReader(strXML); 
XmlSerializer objXmlSerializer = new XmlSerializer(typeof(Automation)); 
Automation automationInstance = (objXmlSerializer.Deserialize(StringReader) as Automation); 
+0

感謝を。私はすでにAutomation.csを行った。私はstrXMLを書くべきですか? – jancooth

+0

この例では、コンテンツがstrXMLという文字列内にあると想定しています。 – Zesty

関連する問題