代码之家  ›  专栏  ›  技术社区  ›  Kevin Korb

asp.net解析要在datalist中使用的xml格式的diffgrams

  •  0
  • Kevin Korb  · 技术社区  · 15 年前

    我有一个方法:

    public static DataSet getTable()
    {
        DataSet DS = new DataSet("My Set");
        DS.ReadXml(getCategories());
        return DS;
    }
    

    mygetCategories()返回包含我的XML的流。

    但是当我运行这个时,我得到一个错误: 提供的XML实例是架构或包含内联架构。此类无法推断架构的架构。

    所以我不知道该怎么办。

    我的目标是使用对gettable()的调用来填充数据列表。

    我试过使用datatable,得到了一个不同但类似的错误。

    任何帮助都很好。

    谢谢。

    这是我的xml文件。可能会有帮助。谢谢。

    <?xml version="1.0" encoding="utf-8"?>
    <WSPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
      <ResponseInteger>0</ResponseInteger>
      <ResponseBoolean>false</ResponseBoolean>
      <ResponseDataset>
        <xs:schema id="CategoryDS" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
          <xs:element name="CategoryDS" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
            <xs:complexType>
              <xs:choice minOccurs="0" maxOccurs="unbounded">
    
                <xs:element name="Category">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="PartCategories" type="xs:string" minOccurs="0" />
                      <xs:element name="CategoryDescriptions" type="xs:string" minOccurs="0" />
                      <xs:element name="CategoryImageURLs" type="xs:string" minOccurs="0" />
                      <xs:element name="CategoryModelFlags" type="xs:string" minOccurs="0" />
                    </xs:sequence>
                  </xs:complexType>
    
                </xs:element>
              </xs:choice>
            </xs:complexType>
          </xs:element>
        </xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <CategoryDS xmlns="">
            <Category diffgr:id="Category1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
              <PartCategories>TESTCAT</PartCategories>
    
              <CategoryDescriptions>TESTING API</CategoryDescriptions>
              <CategoryImageURLs />
              <CategoryModelFlags />
            </Category>
          </CategoryDS>
        </diffgr:diffgram>
      </ResponseDataset>
      <ErrorMessage />
    
      <UserMessage />
    </WSPackage>
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   htkhtk    15 年前

    这与您在其中包含以下XML有关。如果你把它拿出来,它会起作用的。它不会为已经存在的内容创建模式。

            <xs:element name="Category">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="PartCategories" type="xs:string" minOccurs="0" />
                  <xs:element name="CategoryDescriptions" type="xs:string" minOccurs="0" />
                  <xs:element name="CategoryImageURLs" type="xs:string" minOccurs="0" />
                  <xs:element name="CategoryModelFlags" type="xs:string" minOccurs="0" />
                </xs:sequence>
              </xs:complexType>
    
            </xs:element>
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    T