Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Read xml file which has multiple tables

Read xml file which has multiple tables

Scheduled Pinned Locked Moved C#
xml
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ptr_Electron
    wrote on last edited by
    #1

    xml file has multiple tables. I want to read them in and store in a data set... like table[0],table[1]...

    DataSet ds = new DataSet();
    ds.ReadXml("C:\\xmlfile.xml");

    But did not really work Please advice

    I 1 Reply Last reply
    0
    • P ptr_Electron

      xml file has multiple tables. I want to read them in and store in a data set... like table[0],table[1]...

      DataSet ds = new DataSet();
      ds.ReadXml("C:\\xmlfile.xml");

      But did not really work Please advice

      I Offline
      I Offline
      i gr8
      wrote on last edited by
      #2

      How is ur Xml defined?

      P 1 Reply Last reply
      0
      • I i gr8

        How is ur Xml defined?

        P Offline
        P Offline
        ptr_Electron
        wrote on last edited by
        #3

        Here it is...

        <?xml version="1.0" standalone="yes"?>
        <root>
        <Table1>

        <OU ID="1">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="2">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="3">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="4">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>

        </OU>

        </Table1>

        <Table2>
        <OU ID="1">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="2">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="3">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="4">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>

        </OU>

        </Table2>

        <Table3>
        <OU ID="1">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="2">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="3">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>
        </OU>

        <OU ID="4">
        <Col1>ABC</Col1>
        <Col2>XYZ</col2>
        <Col3>17</col3>

        </OU>

        </Table3>

        </root>

        A H 2 Replies Last reply
        0
        • P ptr_Electron

          Here it is...

          <?xml version="1.0" standalone="yes"?>
          <root>
          <Table1>

          <OU ID="1">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="2">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="3">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="4">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>

          </OU>

          </Table1>

          <Table2>
          <OU ID="1">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="2">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="3">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="4">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>

          </OU>

          </Table2>

          <Table3>
          <OU ID="1">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="2">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="3">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>
          </OU>

          <OU ID="4">
          <Col1>ABC</Col1>
          <Col2>XYZ</col2>
          <Col3>17</col3>

          </OU>

          </Table3>

          </root>

          A Offline
          A Offline
          agent00zelda
          wrote on last edited by
          #4

          Dunno if this is the sole reason, but your column tags don't exactly match up... ... ... instead col2 and col3 should be capitalized, Col2 and Col3, to match

          P 1 Reply Last reply
          0
          • A agent00zelda

            Dunno if this is the sole reason, but your column tags don't exactly match up... ... ... instead col2 and col3 should be capitalized, Col2 and Col3, to match

            P Offline
            P Offline
            ptr_Electron
            wrote on last edited by
            #5

            I renamed it when I posted here, Actaully there are same and matching, when I place only one table, It is working fine.

            1 Reply Last reply
            0
            • P ptr_Electron

              Here it is...

              <?xml version="1.0" standalone="yes"?>
              <root>
              <Table1>

              <OU ID="1">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="2">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="3">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="4">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>

              </OU>

              </Table1>

              <Table2>
              <OU ID="1">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="2">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="3">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="4">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>

              </OU>

              </Table2>

              <Table3>
              <OU ID="1">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="2">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="3">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>
              </OU>

              <OU ID="4">
              <Col1>ABC</Col1>
              <Col2>XYZ</col2>
              <Col3>17</col3>

              </OU>

              </Table3>

              </root>

              H Offline
              H Offline
              Harikrishna Daxini
              wrote on last edited by
              #6

              Use xml file like then you will able to read more than one table in dataset by ds.ReadXml(xmlfile) ;Just test it.

              <?xml version="1.0" standalone="yes"?>
              <PersonalInfo>
              <xs:schema id="PersonalInfo" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
              <xs:element name="PersonalInfo" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
              xs:complexType
              <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="PesonalInfo.">
              xs:complexType
              xs:sequence
              <!--Define Column Here....-->
              <xs:element name="name" type="xs:string" />
              <xs:element name="address" type="xs:string" />
              </xs:sequence>
              </xs:complexType>
              </xs:element>
              </xs:choice>
              </xs:complexType>
              </xs:element>
              </xs:schema>
              <!--First Row-->
              <PersonalInfo.>
              <name>abc</name>
              <address>xyz</address>
              </PersonalInfo.>
              <!--Second Row-->
              <!--If You Want To Define-->
              <name>bcd</name>
              <address>ssss</address>
              <!--Please Be CareFull When Enter New Row If There Is No Data To Insert To
              Particular Column Then Write NULL-->

                <xs:schema id="OtherInfo" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
                  <xs:element name="OtherInfo" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
                    <xs:complexType>
                      <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="OtherInfo.">
                          <xs:complexType>
                            <xs:sequence>
                              <!--Define Column Here....-->
                              <xs:element name="name" type="xs:string" />
                              <xs:element name="address" type="xs:string" />
                            </xs:sequence>
                          </xs:complexType>
                      </xs:element>
                      </xs:choice>
                  </xs:complexType>
                  </xs:element>
                </xs:schema>
              

              </PersonalInfo>

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups