How to read below Xml file in C# [Resolved]

Posted by Rajanarayanan under XML on 8/3/2012 | Points: 10 | Views : 2057 | Status : [Member] | Replies : 5
Hi,

I want to read below XML file using c# please help me. I am new in XML Platform..

- <Table>
- <TR>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Age</TD>
</TR>
- <TR>
<TD>Narayanaan</TD>
<TD>Raja</TD>
<TD>24</TD>
</TR>
- <TR>
<TD>Ram</TD>
<TD>Sankar</TD>
<TD>26</TD>
</TR>
- <TR>
<TD>Prem</TD>
<TD>Kanth</TD>
<TD>30</TD>
</TR>
- <TR>
<TD>Raj</TD>
<TD>Yamah</TD>
<TD>32</TD>
</TR>
- <TR>
<TD>Rani</TD>
<TD>Uma</TD>
<TD>29</TD>
</TR>
</Table>

Thanks & Regards
Narayanan P



Responses

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
using System.xml;
XDocument inXML = XDocument.Load("C:\\Test_xml.xml");
foreach (XElement table in from ele in inXML.Descendants("Table").ToList) {
foreach (XElement tr in from el in table.Descendants("TR").ToList) {
foreach (XElement td in from el1 in tr.Descendants("TD").ToList) {
//Ur operation
}
}
}



Regards,
Singaravel M

Rajanarayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/3/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
hi.. @Rajanarayanan
above code are HTML not in XML.
you can read XML from
http://www.java2s.com/Tutorial/XML/CatalogXML.htm

Rajanarayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/6/2012 [Member] Silver | Points: 25

Up
0
Down
which line u need to read?


Regards,
Singaravel M

Rajanarayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajanarayanan on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

I want to like this below format in Grid View reading the above code.Please kindly help me.


First Name Last Name Age
Narayanaan Raja 24
Ram Sankar 26
Prem Kanth 30




Thanks & Regards
Narayanan P

Rajanarayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Calvert on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
Make sure the data is actually readable in UTF8, the way you do this is:Download a notepad that lets you specify the encoding being used to view the document like dataTable.ReadXml() will fail to load as the root 'employee' has 3 levels. Have to use dataSet.ReadXml() and get result from dataSet.Tables[0];
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-grouping

Rajanarayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response