Click here to Skip to main content
15,882,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Im reading a xml data from webservice and while loading it into datatable im getting an error
" Column name id is defined for different mapping types"

XML
<Country id="350" identifier="Montenegro">
    <id>350</id>

    <client id="0" entity-name="ADClient" identifier="System"/>
    <organization id="0" entity-name="Organization" identifier="*"/>
    <active>true</active>
    <creationDate transient="true">2013-01-30T07:35:18.545Z</creationDate>
    <createdBy transient="true" id="0" entity-name="ADUser" identifier="System"/>
    <updated transient="true">2013-01-30T07:35:18.545Z</updated>
    <updatedBy transient="true" id="0" entity-name="ADUser" identifier="System"/>
    <name>Montenegro</name>
    <description>Montenegro</description>
    <iSOCountryCode>ME</iSOCountryCode>
    <hasRegions>false</hasRegions>
    <regionName>State</regionName>
    <phoneNoFormat xsi:nil="true"/>
    <addressPrintFormat>@C@,  @P@</addressPrintFormat>
    <postalCodeFormat xsi:nil="true"/>
    <additionalPostalCode>false</additionalPostalCode>
    <additionalPostalFormat xsi:nil="true"/>
    <default>false</default>
    <language xsi:nil="true"/>
    <currency id="102" entity-name="Currency" identifier="EUR"/>
    <iBANLength>22</iBANLength>
    <iBANCode>ME</iBANCode>
    <decimalseparator xsi:nil="true"/>
    <groupingseparator xsi:nil="true"/>
    <numericmask xsi:nil="true"/>
    <dateformat xsi:nil="true"/>
    <datetimeformat xsi:nil="true"/>
    <countryTrlList/>
    <regionList/>
  </Country>




Since id is used both as attribute and element,ther is a conflict between the name id.. How can i rename it or resolve it ....i cannot the change the webservice since i dont ve access to it

the code m using to load the datatable is
Java
DataTable dt = new DataTable();
  using (var client = new WebClient { Credentials =new NetworkCredential("Username","Password") })
            {
               string  result = client.DownloadString(uri);
               XmlTextReader reader = new XmlTextReader(new StringReader(result));
               dt.ReadXml(reader);
              return dsGetValues;
            }

Thanks
Darshan
Posted
Updated 8-Jul-13 22:06pm
v4

1 solution

Try this

static void Main(string[] args)
{
   DataSet ds = new DataSet();
   ds.EnforceConstraints = false;
   ds.ReadXmlSchema("XMLSchema1.xsd");
   XmlTextReader reader = new XmlTextReader("XMLFile1.xml");
   ds.ReadXml(reader);
}


I have saved your xml in file named "XMLFile1.xml" and created XSD named "XMLSchema1.xsd". Below is the content of XSD. Hoping this should solve your problem.

XML
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Country">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:short" name="Id"/>
        <xs:element name="client">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:short" name="id"/>
                <xs:attribute type="xs:string" name="entity-name"/>
                <xs:attribute type="xs:string" name="identifier"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="organization">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:short" name="id"/>
                <xs:attribute type="xs:string" name="entity-name"/>
                <xs:attribute type="xs:string" name="identifier"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element type="xs:string" name="active"/>
        <xs:element name="creationDate">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:dateTime">
                <xs:attribute type="xs:string" name="transient"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="createdBy">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="transient"/>
                <xs:attribute type="xs:short" name="id"/>
                <xs:attribute type="xs:string" name="entity-name"/>
                <xs:attribute type="xs:string" name="identifier"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="updated">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:dateTime">
                <xs:attribute type="xs:string" name="transient"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="updatedBy">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="transient"/>
                <xs:attribute type="xs:short" name="id"/>
                <xs:attribute type="xs:string" name="entity-name"/>
                <xs:attribute type="xs:string" name="identifier"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element type="xs:string" name="name"/>
        <xs:element type="xs:string" name="description"/>
        <xs:element type="xs:string" name="iSOCountryCode"/>
        <xs:element type="xs:string" name="hasRegions"/>
        <xs:element type="xs:string" name="regionName"/>
        <xs:element type="xs:string" name="phoneNoFormat"/>
        <xs:element type="xs:string" name="addressPrintFormat"/>
        <xs:element type="xs:string" name="postalCodeFormat"/>
        <xs:element type="xs:string" name="additionalPostalCode"/>
        <xs:element type="xs:string" name="additionalPostalFormat"/>
        <xs:element type="xs:string" name="default"/>
        <xs:element type="xs:string" name="language"/>
        <xs:element name="currency">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute type="xs:short" name="id"/>
                <xs:attribute type="xs:string" name="entity-name"/>
                <xs:attribute type="xs:string" name="identifier"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element type="xs:short" name="iBANLength"/>
        <xs:element type="xs:string" name="iBANCode"/>
        <xs:element type="xs:string" name="decimalseparator"/>
        <xs:element type="xs:string" name="groupingseparator"/>
        <xs:element type="xs:string" name="numericmask"/>
        <xs:element type="xs:string" name="dateformat"/>
        <xs:element type="xs:string" name="datetimeformat"/>
        <xs:element type="xs:string" name="countryTrlList"/>
        <xs:element type="xs:string" name="regionList"/>
      </xs:sequence>
      <xs:attribute type="xs:short" name="id"/>
      <xs:attribute type="xs:string" name="identifier"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900