Read xml file which has multiple tables
-
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
-
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
-
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>
-
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>
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
-
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
I renamed it when I posted here, Actaully there are same and matching, when I place only one table, It is working fine.
-
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>
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>