IT Community - Software Programming, Web Development and Technical Support

How to use the XML Reader in C# .net ?

This is a discussion on How to use the XML Reader in C# .net ? within the C# Programming forums, part of the Software Development category; How to use the XML Reader in C# .net ?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-18-2007, 11:00 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question How to use the XML Reader in C# .net ?

How to use the XML Reader in C# .net ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-19-2007, 12:49 AM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default Re: How to use the XML Reader in C# .net ?

Read the xml values using XMLTEXTREADER


Goals:

This project is used to read the xml value using c#.


Steps:

1) Create xml like:

<India>
<State>Tamil Nadu</State>
<State>Andhra Pradesh</State>
<State>Karnataka</State>
<State>Maharastira</State>
<State>Kerala</State>
<State>West Bengal</State>
<State>Misoram</State>
<State>Kashmir</State>
</India>


2) In the aspx.cs file copy the following code:


protected void Page_Load(object sender, EventArgs e)
{
Response.Write(ReadXML(Server.MapPath("reader.xml" )));
}
public string ReadXML(string xmlUrl)
{
System.Text.StringBuilder sbXML = new System.Text.StringBuilder();
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(xmlUrl);

object oProvinceName = reader.NameTable.Add("State");

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(oProvinceName))
{
sbXML.Append(reader.ReadString()).Append("<br />");
}
}
}
return sbXML.ToString();
}
catch (Exception e)
{
Response.Write(e.Message);
return "";
}
finally
{

if (reader != null)
reader.Close();
}
}

3) run the project.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Barcode reader Jeyaseelansarc PHP Programming 0 07-18-2007 11:56 PM


All times are GMT -7. The time now is 05:12 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0