none
Dataset.ReadXmlSchema error " Data type not defined." RRS feed

  • Question

  • when i try to read xsd using the ReadXmlSchema method am getting an exception data type not defined,

    if i  change the maxOccurs="0" to maxOccurs="1" of Hdr type then the function will working correctly,

     see the XSD below 

     

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    
     <xs:complexType name="Hdr">
     <xs:simpleContent>
      <xs:extension base="xs:string">
      <xs:attribute name="name" use="required">
       <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="" />
       </xs:restriction>
       </xs:simpleType>
      </xs:attribute>  
      <xs:attribute name="mark" use="optional">
       <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="BLANK" />
       </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
      </xs:extension>
     </xs:simpleContent>
     </xs:complexType>
     
     <xs:complexType name="RecordFldType">
     <xs:simpleContent>
      <xs:extension base="xs:string">
      <xs:attribute name="name" use="required">
       <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="type_A|type_B" />
       </xs:restriction>
       </xs:simpleType>
      </xs:attribute>  
      <xs:attribute name="mark" use="optional">
       <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="BLANK" />
       </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
      </xs:extension>
     </xs:simpleContent>
     </xs:complexType>
     <xs:complexType name="Rec">
     <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="11" type="RecordFldType" name="Fld" />
     </xs:sequence>
     <xs:attribute name="ord" type="xs:unsignedShort" use="required" />
     <xs:attribute name="y" type="xs:unsignedShort" use="optional" />
     </xs:complexType>
     <xs:element name="Batch" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
     <xs:complexType>
      <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="unbounded" name="Img">
       <xs:complexType>
       <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Section">
        <xs:complexType>
         <xs:sequence>
         <xs:element minOccurs="0"<strong> maxOccurs="0"</strong> type="Hdr" name="Fld" />
         <xs:element maxOccurs="unbounded" minOccurs="0" type="Rec" name="Rd" />
         </xs:sequence>
         <xs:attribute name="ord" type="xs:unsignedShort" use="required" />
        </xs:complexType>
        </xs:element>
       </xs:sequence>
       <xs:attribute name="type" use="required">
        <xs:simpleType>
        <xs:restriction base="xs:string">
         <xs:pattern value="Bad|Blank|Duplicate" />
        </xs:restriction>
        </xs:simpleType>
       </xs:attribute>
       <xs:attribute name="ord" type="xs:unsignedShort" use="required" />
       <xs:attribute name="img" use="required">
        <xs:simpleType>
        <xs:restriction base="xs:string">
         <xs:pattern value="^[1-9]\d*\.\w{3}$" />
        </xs:restriction>
        </xs:simpleType>
       </xs:attribute>
       </xs:complexType>
      </xs:element>
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" use="required" />
     </xs:complexType>
     <xs:unique name="pk_Img">
      <xs:selector xpath="Img" />
      <xs:field xpath="@img" />
     </xs:unique>
     </xs:element>
    </xs:schema>
    
    Please help,

     

     

    • Moved by Mike Dos Zhang Wednesday, October 13, 2010 1:14 PM xml topic (From:Visual C# General)
    • Moved by Xianfeng Zhang Thursday, October 14, 2010 5:52 AM The exception is thrown from system.data assembly instead of system.xml assembly. (From:XML and the .NET Framework)
    Monday, October 11, 2010 11:46 AM

All replies

  • Hello,

    Try this link out and see if its any help: http://forums.asp.net/t/683228.aspx


    Ankit
    • Proposed as answer by AnkitMathur Monday, October 11, 2010 6:47 PM
    • Unproposed as answer by Xianfeng Zhang Thursday, October 14, 2010 4:57 AM
    Monday, October 11, 2010 5:54 PM
  • sorry to say, the link didn't helped me. my problem is the XSD file with change time to time, so i cant change the maxOccurs value every time.

    Any idea why the exception is occurring?

    Tuesday, October 12, 2010 6:35 AM
  • Hi  nrmohan,

    Welcome to MSDN Forums!

     

    I move this thread here because of it's likely to get quicker and better responses to xml issues at http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/threads where xml experts live in.

     

    If there’s anything unclear, please feel free to let me know.

     

    Best wishes,

    Mike

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Wednesday, October 13, 2010 1:14 PM
  • Hi

    Thanks for the post. I reproduced that exception which is thrown by System.Data.XSDSchema.HandleElementColumn(). It's not thrown from system.xml library. So it need some guy from system.data for better explanation. My guess is that because the maxoccus = "0", this type is optimized off and cannot be found.

    Unhandled Exception: System.Data.DataException: Data type not defined.
       at System.Data.XSDSchema.HandleElementColumn(XmlSchemaElement elem, DataTable
     table, Boolean isBase)
       at System.Data.XSDSchema.HandleParticle(XmlSchemaParticle pt, DataTable table
    , ArrayList tableChildren, Boolean isBase)
       at System.Data.XSDSchema.HandleComplexType(XmlSchemaComplexType ct, DataTable
     table, ArrayList tableChildren, Boolean isNillable)
       at System.Data.XSDSchema.InstantiateTable(XmlSchemaElement node, XmlSchemaCom
    plexType typeNode, Boolean isRef)
       at System.Data.XSDSchema.HandleTable(XmlSchemaElement node)
       at System.Data.XSDSchema.HandleParticle(XmlSchemaParticle pt, DataTable table
    , ArrayList tableChildren, Boolean isBase)
       at System.Data.XSDSchema.HandleComplexType(XmlSchemaComplexType ct, DataTable
     table, ArrayList tableChildren, Boolean isNillable)
       at System.Data.XSDSchema.InstantiateTable(XmlSchemaElement node, XmlSchemaCom
    plexType typeNode, Boolean isRef)
       at System.Data.XSDSchema.HandleTable(XmlSchemaElement node)
       at System.Data.XSDSchema.HandleDataSet(XmlSchemaElement node, Boolean isNewDa
    taSet)
       at System.Data.XSDSchema.LoadSchema(XmlSchemaSet schemaSet, DataSet ds)
       at System.Data.DataSet.ReadXSDSchema(XmlReader reader, Boolean denyResolving)

       at System.Data.DataSet.ReadXmlSchema(XmlReader reader, Boolean denyResolving)

       at System.Data.DataSet.ReadXmlSchema(String fileName)
       at testXSD.Program.Main(String[] args) in d:\test\testXML\testXSD\Program.cs:

    Thursday, October 14, 2010 5:50 AM
  • hi,

    thanks for the information, i am using the xsd to create the xml using the DataSet.WriteXml Method, so for doing this i need to read the xml schema, am stuck at this point.

    is there any other way to generate xml from the xsd? 

    Please help

     

     


    Thursday, October 14, 2010 6:12 AM