?
Solved

Cannot read XML file into DataSet...

Posted on 2011-03-25
10
Medium Priority
?
2,353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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