Solved

Cannot read XML file into DataSet...

Posted on 2011-03-25
10
2,198 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 74

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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 74

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

17 Experts available now in Live!

Get 1:1 Help Now