C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to store XML File In String Builder


Posted Date: 30 Jul 2008      Total Responses: 4

Posted By: pattankhaleelullla khan       Member Level: Bronze     Points: 1



I have this XML File,
I want to store the Entire XML File in to Srting Builder when ima generating Itself.
Please send code snippet.
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <all_Programs>
- <State name="sax">
- <City name="Alabama">
- <Programe name="xcv">
<Location name="xc" />
</Programe>
</City>
</State>
- <State name="San Jone">
- <City name="California">
- <Programe name="z">
<Location name="x" />
</Programe>
</City>
</State>
</all_Programs>




Responses

Author: Shivshanker Cheral    30 Jul 2008Member Level: DiamondRating:     Points: 0
refer for reading xml and storing

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
//Location of XML file
string xmlFilePath = MapPath("Employees.xml");
try{
using (XmlReader reader = XmlReader.Create(xmlFilePath)){
string result;
while (reader.Read())
{
//Process only the elements
if (reader.NodeType == XmlNodeType.Element)
{
//Reset the variable for a new element
result = "";
for (int count = 1; count <= reader.Depth; count++)
{
result += "===";
}
result += "=> " + reader.Name + "<br/>";
lblResult.Text += result;
}
}
}
}
catch (Exception ex)
{
lblResult.Text = "An Exception occurred: " + ex.Message;
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Reading an XML File using XmlReader</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="lblResult" runat="server" />
</div>
</form>
</body>
</html>

<%--
<?xml version='1.0'?>
<employees>
<employee id="1">
<name>
<firstName>Nancy</firstName>
<lastName>Lee</lastName>
</name>
<city>Seattle</city>
<state>WA</state>
<zipCode>98122</zipCode>
</employee>
<employee id="2">
<name>
<firstName>Jason</firstName>
<lastName>Wang</lastName>
</name>
<city>Vancouver</city>
<state>WA</state>
<zipCode>98123</zipCode>
</employee>
</employees>

--%>




Author: Nagarajan    30 Jul 2008Member Level: GoldRating:     Points: 3
As far as you could get your XML data (read from the xml), Create an string builder for it.

StringBuilder xmlBuilder = new StringBuilder(stringXmlData);
[\CODE]


Author: Sabu C Alex    31 Jul 2008Member Level: GoldRating:     Points: 4
hi if you want to read xml from a file and append that to stringbuilder

then use like this

TextReader tr = new StreamReader("Your file name");
if (tr.Peek() != -1)
{
StringBuilder sb = new StringBuilder();
sb.Append(tr.ReadToEnd());
}
tr.close()




Author: Deepa    31 Jul 2008Member Level: DiamondRating:     Points: 6
<%@ Page Language="C#" %><%@ Import Namespace="System.Xml" %><script runat="server"> void Page_Load(object sender, EventArgs e) { //Location of XML file string xmlFilePath = MapPath("Employees.xml"); try{ using (XmlReader reader = XmlReader.Create(xmlFilePath)){ string result; while (reader.Read()) { //Process only the elements if (reader.NodeType == XmlNodeType.Element) { //Reset the variable for a new element result = ""; for (int count = 1; count <= reader.Depth; count++) { result += "==="; } result += "=> " + reader.Name + "<br/>"; lblResult.Text += result; } } } } catch (Exception ex) { lblResult.Text = "An Exception occurred: " + ex.Message; } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Reading an XML File using XmlReader</title></head><body> <form id="form1" runat="server"> <div> <asp:label id="lblResult" runat="server" /> </div> </form></body></html><%--<?xml version='1.0'?><employees> <employee id="1"> <name> <firstName>Nancy</firstName> <lastName>Lee</lastName> </name> <city>Seattle</city> <state>WA</state> <zipCode>98122</zipCode> </employee> <employee id="2"> <name> <firstName>Jason</firstName> <lastName>Wang</lastName> </name> <city>Vancouver</city> <state>WA</state> <zipCode>98123</zipCode> </employee> </employees>--%>


Post Reply
You must Sign In to post a response.
Next : reading an xml file,windows application
Previous : pls solve the error in below code..(XML)
Return to Discussion Forum
Post New Message
Category: XML

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use