使用ReadXmlSchema

时间:2015-07-30 10:35:16

标签: c# .net xml xsd dataset

我尝试使用ReadXmlSchema方法从架构加载数据集列。 它正在工作但是0列负载。我看不出xsd文件有任何问题。这是我的xsd文件:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns3="http://tempuri.org/Ortak_Tip.xsd" xmlns:ns4="http://tempuri.org/Ortak_Risk.xsd" xmlns:ns5="http://tempuri.org/Ek.xsd" xmlns:t="http://tempuri.org/Form.xsd" targetNamespace="http://tempuri.org/Form.xsd" elementFormDefault="qualified">
<xsd:import namespace="http://tempuri.org/Ortak_Tip.xsd" schemaLocation="http://tempuri.org/Ortak_Tip.xsd"/>
<xsd:import namespace="http://tempuri.org/Ortak_Risk.xsd" schemaLocation="http://tempuri.org/Ortak_Risk.xsd"/>
<xsd:import  namespace="http://tempuri.org/Ek.xsd" schemaLocation="http://tempuri.org/Ek.xsd"/>
<xsd:element name="Form">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="Veri">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="Satir" maxOccurs="unbounded">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="SiraNo" type="ns3:Sayi15"/>
<xsd:element name="KrediIslemHesapNo" type="ns4:Karakter60"/>
<xsd:element name="MusteriNo" type="ns5:Karakter25"/>
<xsd:element name="VergiNo" type="ns4:Sayi11" nillable="true"/>
<xsd:element name="Adi" type="ns3:Karakter255"/>
<xsd:element name="UlkeKodu" type="ns3:UlkeKodu"/>
<xsd:element name="IslemTuru" type="xsd:boolean"/>
<xsd:element name="TarafKodu" type="ns3:IslemTarafKodu"/>
<xsd:element name="MusteriRiskSinif" type="ns4:MusterininRiskSinifi2"/>
<xsd:element name="IslemTutarAnaparaTLKarsilik" type="ns5:Yuzde14_2"/>
<xsd:element name="IslemTutarFaizTLKarsilik" type="ns5:Yuzde14_2"/>
<xsd:element name="IslemTutarToplamTLKarsilik" type="ns5:Yuzde14_2"/>
<xsd:element name="IslemOrijinalParaKodu" type="ns3:ParaKodu2"/>
<xsd:element name="ParaKoduEndeks" type="ns3:ParaKoduEndeks" nillable="true"/>
<xsd:element name="MKIhracciUnvan" type="ns3:Karakter255"/>
<xsd:element name="MKISINKodu" type="ns3:Karakter12"/>
<xsd:element name="PiyasaFiyatTLKarsilik" type="ns5:Yuzde14_2"/>
<xsd:element name="MKParaKodu" type="ns3:ParaKodu2"/>
<xsd:element name="MKVade" type="xsd:date" nillable="true"/>
<xsd:element name="IslemVade" type="xsd:date"/>
<xsd:element name="Portfoy" type="ns4:Portfoy2"/>
<xsd:element name="BilancoDeger" type="ns5:Yuzde14_2"/>
<xsd:element name="NominalDeger" type="ns5:Yuzde14_2"/>
<xsd:element name="AlacakVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
<xsd:element name="KurVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
<xsd:element name="TeminatVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
<xsd:element name="KarsiTarafRiskAgirlik" type="ns3:Sayi4" nillable="true"/>
<xsd:element name="TeminatRiskAgirlik" type="ns3:Sayi4" nillable="true"/>
<xsd:element name="RAV" type="ns5:Yuzde14_2" nillable="true"/>
<xsd:element name="IslemTHPKodu" type="ns3:Karakter8"/>
<xsd:element name="MKTHPKodu" type="ns3:Karakter8" nillable="true"/>
<xsd:element name="MKSinif" type="ns4:MKIslemSinif"/>
<xsd:element name="IslemSinif" type="ns4:MKIslemSinif"/>
<xsd:element name="EmanetDurumu" type="ns3:Karakter255"/>
<xsd:element name="IlaveTeminat" type="xsd:boolean"/>
<xsd:element name="KRATSonraRAV" type="ns5:Yuzde14_2" nillable="true"/>
<xsd:element name="KarsiTarafDerecelendirmeNotu1" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="KarsiTarafDerecelendirmeNotu2" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="KarsiTarafDerecelendirmeNotu3" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="KarsiTarafDerecelendirmeNotu4" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="MKDerecelendirmeNotu1" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="MKDerecelendirmeNotu2" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="MKDerecelendirmeNotu3" type="ns5:Karakter25" nillable="true"/>
<xsd:element name="MKDerecelendirmeNotu4" type="ns5:Karakter25" nillable="true"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="Gun" type="ns4:Gun" use="required" fixed="1"/>
<xsd:attribute name="Ay" type="ns4:Ay" use="required"/>
<xsd:attribute name="Yil" type="ns3:Sayi4" use="required"/>
<xsd:attribute name="FormKodu" type="ns3:Karakter7" use="required" fixed="RT100AS"/>
<xsd:attribute name="KurulusKodu" type="ns5:Sayi3" use="required"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>

有人可以告诉我哪里错了吗?

2 个答案:

答案 0 :(得分:0)

  

它在工作......

这不可信。

  

...但是0列加载。

现在这是可信的。

一个直接明显的问题是,您的XSD的schemaLocations中的xsd:import所提供的网址会重定向到www.bing.com。在此之前,您必须解决此问题。

答案 1 :(得分:-1)

xsd名称空间不像嵌套标签。您还需要一个根元素。进行更改以获取要读取的xml。不确定这是否是你真正需要的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(FILENAME, XmlReadMode.ReadSchema);
        }

    }



}

XML

<?xml version="1.0" encoding="utf-8" ?>
<Root xsd:schema="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001" xmlns:ns3="http://tempuri.org/Ortak_Tip.xsd" xmlns:ns4="http://tempuri.org/Ortak_Risk.xsd" xmlns:ns5="http://tempuri.org/Ek.xsd" xmlns:t="http://tempuri.org/Form.xsd" targetNamespace="http://tempuri.org/Form.xsd" elementFormDefault="qualified">
  <xsd:import namespace="http://tempuri.org/Ortak_Tip.xsd" schemaLocation="http://tempuri.org/Ortak_Tip.xsd"/>
  <xsd:import namespace="http://tempuri.org/Ortak_Risk.xsd" schemaLocation="http://tempuri.org/Ortak_Risk.xsd"/>
  <xsd:import  namespace="http://tempuri.org/Ek.xsd" schemaLocation="http://tempuri.org/Ek.xsd"/>
  <xsd:element name="Form">
    <xsd:complex>
      <xsd:complexSequence>
        <xsd:restriction base="xsd:anyType">
          <xsd:sequence>
            <xsd:elementSequence name="Veri">
              <xsd:complexContent>
                <xsd:complexType>
                  <xsd:restrictionType base="xsd:anyType">
                    <xsd:sequenceType>
                      <xsd:table name="Satir" maxOccurs="unbounded">
                        <xsd:elementAttribute>
                          <xsd:complexAttribute>
                            <xsd:restrictionAttribute base="xsd:anyType">
                              <xsd:sequenceAttribute>
                                <xsd:attribute name="SiraNo" type="ns3:Sayi15"/>
                                <xsd:attribute name="KrediIslemHesapNo" type="ns4:Karakter60"/>
                                <xsd:attribute name="MusteriNo" type="ns5:Karakter25"/>
                                <xsd:attribute name="VergiNo" type="ns4:Sayi11" nillable="true"/>
                                <xsd:attribute name="Adi" type="ns3:Karakter255"/>
                                <xsd:attribute name="UlkeKodu" type="ns3:UlkeKodu"/>
                                <xsd:attribute name="IslemTuru" type="xsd:boolean"/>
                                <xsd:attribute name="TarafKodu" type="ns3:IslemTarafKodu"/>
                                <xsd:attribute name="MusteriRiskSinif" type="ns4:MusterininRiskSinifi2"/>
                                <xsd:attribute name="IslemTutarAnaparaTLKarsilik" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="IslemTutarFaizTLKarsilik" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="IslemTutarToplamTLKarsilik" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="IslemOrijinalParaKodu" type="ns3:ParaKodu2"/>
                                <xsd:attribute name="ParaKoduEndeks" type="ns3:ParaKoduEndeks" nillable="true"/>
                                <xsd:attribute name="MKIhracciUnvan" type="ns3:Karakter255"/>
                                <xsd:attribute name="MKISINKodu" type="ns3:Karakter12"/>
                                <xsd:attribute name="PiyasaFiyatTLKarsilik" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="MKParaKodu" type="ns3:ParaKodu2"/>
                                <xsd:attribute name="MKVade" type="xsd:date" nillable="true"/>
                                <xsd:attribute name="IslemVade" type="xsd:date"/>
                                <xsd:attribute name="Portfoy" type="ns4:Portfoy2"/>
                                <xsd:attribute name="BilancoDeger" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="NominalDeger" type="ns5:Yuzde14_2"/>
                                <xsd:attribute name="AlacakVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
                                <xsd:attribute name="KurVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
                                <xsd:attribute name="TeminatVolAyarKatsayi" type="ns4:Yuzde5_3" nillable="true"/>
                                <xsd:attribute name="KarsiTarafRiskAgirlik" type="ns3:Sayi4" nillable="true"/>
                                <xsd:attribute name="TeminatRiskAgirlik" type="ns3:Sayi4" nillable="true"/>
                                <xsd:attribute name="RAV" type="ns5:Yuzde14_2" nillable="true"/>
                                <xsd:attribute name="IslemTHPKodu" type="ns3:Karakter8"/>
                                <xsd:attribute name="MKTHPKodu" type="ns3:Karakter8" nillable="true"/>
                                <xsd:attribute name="MKSinif" type="ns4:MKIslemSinif"/>
                                <xsd:attribute name="IslemSinif" type="ns4:MKIslemSinif"/>
                                <xsd:attribute name="EmanetDurumu" type="ns3:Karakter255"/>
                                <xsd:attribute name="IlaveTeminat" type="xsd:boolean"/>
                                <xsd:attribute name="KRATSonraRAV" type="ns5:Yuzde14_2" nillable="true"/>
                                <xsd:attribute name="KarsiTarafDerecelendirmeNotu1" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="KarsiTarafDerecelendirmeNotu2" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="KarsiTarafDerecelendirmeNotu3" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="KarsiTarafDerecelendirmeNotu4" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="MKDerecelendirmeNotu1" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="MKDerecelendirmeNotu2" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="MKDerecelendirmeNotu3" type="ns5:Karakter25" nillable="true"/>
                                <xsd:attribute name="MKDerecelendirmeNotu4" type="ns5:Karakter25" nillable="true"/>
                              </xsd:sequenceAttribute>
                            </xsd:restrictionAttribute>
                          </xsd:complexAttribute>
                        </xsd:elementAttribute>
                      </xsd:table>
                    </xsd:sequenceType>
                  </xsd:restrictionType>
                </xsd:complexType>
              </xsd:complexContent>
            </xsd:elementSequence>
          </xsd:sequence>
          <xsd:attribute name="Gun" type="ns4:Gun" use="required" fixed="1"/>
          <xsd:attribute name="Ay" type="ns4:Ay" use="required"/>
          <xsd:attribute name="Yil" type="ns3:Sayi4" use="required"/>
          <xsd:attribute name="FormKodu" type="ns3:Karakter7" use="required" fixed="RT100AS"/>
          <xsd:attribute name="KurulusKodu" type="ns5:Sayi3" use="required"/>
        </xsd:restriction>
      </xsd:complexSequence>
    </xsd:complex>
  </xsd:element>
  <!--</xsd:schema>-->
</Root>