Solved

Cannot read XML file into DataSet...

Posted on 2011-03-25
10
2,249 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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