Solved

Cannot read XML file into DataSet...

Posted on 2011-03-25
10
2,229 Views
Last Modified: 2013-12-17
I have this code in C# to read the XML into DataSet
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("data.xml"));

and I get this error, when it reads the file...

A column named 'tables' already belongs to this DataTable: cannot set a nested table name to the same name.
0
Comment
Question by:evo_x
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35220163
Does you XML look like this (structure-wise)?
<someRoot>
    <tables>
        <someChild />
        <someChild />
    </tables>
    <tables>
        <someChild />
        <someChild />
    <tables>
</someRoot>

Open in new window

0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35220604
0
 
LVL 2

Author Comment

by:evo_x
ID: 35222734
Hi,
   This is how my XML file looks like, I have attached the file.

XMLFile.xml
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 20

Expert Comment

by:informaniac
ID: 35223495
Dataset ds = new Dataset("myTable");
0
 
LVL 2

Author Comment

by:evo_x
ID: 35223732
setting the table name in Dataset constructor still does not work
1
 
LVL 20

Expert Comment

by:informaniac
ID: 35226521
<table name="PageNavigation">

<table name="AdLinks">


<table name="PhotoLinks">

Change the names from table to something else. And then try...
0
 
LVL 2

Author Comment

by:evo_x
ID: 35226779
I have tried and I still get the same error
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35228460
>>  I have tried and I still get the same error

Trust me, you're not getting *exactly* the same error. You are getting the same type of error, but with different affected nodes. You have repeated node names at several levels. It took me a couple of minutes to sort them all out, but they are there.

Here is a modified file that did load for me:
<?xml version="1.0" encoding="UTF-8"?>
<data_project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <table name="Carsforsale3">
    <rows>
      <row>
        <columns>
          <column name="start_url"><![CDATA[http://www.mysite.com]]></column>
        </columns>
        <tables>
          <table1 name="PageNavigation">
            <rows1>
              <row1>
                <columns>
                  <column name="page"><![CDATA[1]]></column>
                </columns>
                <tables2>
                  <table2 name="AdLinks">
                    <rows2>
                      <row2>
                        <columns>
                          <column name="AdTitle"><![CDATA[2000 Cadillac Deville]]></column>
                          <column name="Year"><![CDATA[2000]]></column>
                          <column name="Make"><![CDATA[Cadillac]]></column>
                          <column name="Model"><![CDATA[Deville]]></column>
                          <column name="VehicleDescription"><![CDATA[Vehicle Description INTRODUCING THE 2000 CADILLAC DTS! THIS IS A CARFAX CERTIFIED, VERY WELL MAINTAINED VEHICLE WITH ONLY 69K MILES! IT IS EQUIPPED WITH EXTRA OPTIONS SUCH AS PREMIUM WHEELS, HEATED FRONT AND BACK SEATS, KEYLESS ENTRY SYSTEM AND MUCH MORE! ALL THE OPTIONS FUNCTION ACCORDINGLY! THE V8 ENGINE RUNS GREAT AND AUTOMATIC TRANSMISSION SHIFTS SMOOTHLY INTO GEARS ! THE WHITE EXTERIOR IS IN GOOD AND HEALTHY CONDITION AND THE TAN INTERIOR HAS BEEN KEPT VERY CLEAN! THE OVERALL CONDITION OF THIS VEHICLE IS GREAT, SO DON'T WAIT AND CALL US NOW! FOR MORE INFORMATION AND SPECS OF THE VEHICLE, VISIT WWW.EDMUNDS.COM]]></column>
                          <column name="VehicleOptions"><![CDATA[4 Door, Automatic Transmission, Premium Wheels, Air Conditioning, Cruise Control, Leather Seats, Power Steering, Power Windows, Keyless Entry]]></column>
                          <column name="Engine"><![CDATA[8-Cylinder V8]]></column>
                          <column name="Transmission"><![CDATA[4 Speed Automatic]]></column>
                          <column name="Color"><![CDATA[WHITE]]></column>
                          <column name="BodyStyle"><![CDATA[Gasoline]]></column>
                          <column name="Trim"><![CDATA[DTS]]></column>
                          <column name="MPG"><![CDATA[17 city / 28 hwy]]></column>
                          <column name="Interior"><![CDATA[TAN]]></column>
                        </columns>
                        <tables3>
                          <table3 name="PhotoLinks">
                            <rows3>
                              <row3>
                                <columns>
                                  <column name="Photo"><![CDATA[C:\img.jpg]]></column>
                                  <column name="Photo_url"><![CDATA[http://images.mysite.com/19B61181-C158-4371-8215-4EFA84A9273C_1.jpg]]></column>
                                </columns>
                                <tables>
                                </tables>
                              </row3>
                              <row3>
                                <columns>
                                  <column name="Photo"><![CDATA[C:\img.jpg]]></column>
                                  <column name="Photo_url"><![CDATA[http://images.mysite.com/287312/19B61181-C158-4371-8215-4EFA84A9273C_2.jpg]]></column>
                                </columns>
                                <tables4>
                                </tables4>
                              </row3>
                            </rows3>
                          </table3>
                        </tables3>
                      </row2>
                    </rows2>
                  </table2>
                </tables2>
              </row1>
            </rows1>
          </table1>
        </tables>
      </row>
    </rows>
  </table>
</data_project>

Open in new window

0
 
LVL 2

Author Comment

by:evo_x
ID: 35228790
You are right, now it loads the XML file, the problem is that I have thousands of records in the XML file and I cannot rename each table and row manually and I will also end up having thousands of different tables instead of records in a singe table
0
 
LVL 2

Author Comment

by:evo_x
ID: 35228792
The DataSet should load all records in the coresponding table instead of creating a different table for each row...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now