【问题标题】:Load Dataset Columns From Xsd using ReadXmlSchema使用 ReadXmlSchema 从 Xsd 加载数据集列
【发布时间】:2015-07-30 10:35:15
【问题描述】:

我尝试使用 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>

谁能告诉我哪里错了?

【问题讨论】:

    标签: c# .net xml xsd dataset


    【解决方案1】:

    它正在工作......

    这不可信。

    ...但 0 列加载。

    现在这是可信的。

    一个显而易见的问题是,XSD 的 xsd:imports 中的 schemaLocations 给出的 URL 重定向到 www.bing.com。首先,您必须解决此问题。

    【讨论】:

      【解决方案2】:

      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>
      

      【讨论】:

      • xsd 命名空间不喜欢嵌套标签。我无法想象对该语句的解释是有意义的。
      • 您还需要一个根元素。 OP 有一个根元素;根本没有缩进来显示它。
      • 最后,为什么要用人为的Root 元素替换OP 的根xsd:schema 元素?
      • 尝试以下操作:在 vs 从菜单中:项目:添加新项目:XML 文件。将 OP 原始 XML 粘贴到新视图中,确保只存在一个 xml 标识行。然后打开 vs 错误列表。你会看到很多警告。然后用我的 xml 重复。当我的更改确实导入时,原始 xml 文件将不会导入。修复原始xml的方法有很多。如果您有更好的方法来修复 xml,请告诉我。
      • 你忽略了我在你的回答中提出的所有三个问题,只是为了描述一个完全混淆 OP 的 xsd:import 问题的过程,通过吹走他的 xsd:schema 根元素,以便 VS 不再认为这是一个 XSD。 对不起,这个答案完全错误,无法保存;它应该被删除。
      猜你喜欢
      • 2010-09-16
      • 2012-03-23
      • 1970-01-01
      • 2012-06-21
      • 2020-07-27
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多