Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot read XML file into DataSet...

Posted on 2011-03-25
10
Medium Priority
?
2,416 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

609 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