Can Somebody please help me with the below codes, I really appreciates anyone help.
Below are my C# codes, the purpose of this code is to replace the attributes inside the XML file
protected void GenerateXML(object sender, EventArgs e)
{
string path;
string txtfile;
path = Server.MapPath("~\\Temp\\myxml.xml");
string dpath = Server.MapPath("~\\Download\\");
txtfile = File.ReadAllText(path);
foreach (GridViewRow srow in Main.Rows)
{
string batype = srow.Cells[0].Text;
string apath = dpath + "XML_Report";
if (!Directory.Exists(apath))
Directory.CreateDirectory(apath);
string Outxmlfile = apath + ".xml";
if (!File.Exists(Outxmlfile))
{
using (StreamWriter txtsw = File.CreateText(Outxmlfile))
{
txtsw.WriteLine(txtfile);
}
txtfile = txtfile.Replace(("<celName>"), batype);
File.WriteAllText(Outxmlfile, txtfile);
}
}
}
Below are my codes for my Gridview named as "Main"
<div class="tabContents">
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="View1" runat="server">
<asp:GridView ID="Main" runat="server" AllowUserToAddRows="False" HorizontalAlign="Left" Font-Bold="True" Height="10px" AllowSorting="True">
<HeaderStyle BackColor="#FF9966" Font-Bold="True" Font-Size="Large" ForeColor="White" Wrap="False" />
</asp:GridView>
</asp:View>
</asp:MultiView>
</div>
The template I used is myxml.xml containing below elements:
<mainelement>
<p name="BatteryCellName"><celName></p>
<p name="BatteryCellName"><celName></p>
<p name="BatteryCellName"><celName></p>
</mainelement>
I wanted to replace the attribute celName with the one showing in the Gridview enter image description here
I want the output to be below:
<mainelement>
<p name="BatteryCellName">Lithium-ion</p>
<p name="BatteryCellName">Nickel Cadmium</p>
<p name="BatteryCellName">Nickel-Metal Hydride</p>
</mainelement>
But everytime I run my c# could it will display only the Lithium-ion. Can somebody help me I'm a newbie:-)
<mainelement>
<p name="BatteryCellName">Lithium-ion</p>
<p name="BatteryCellName">Lithium-ion</p>
<p name="BatteryCellName">Lithium-ion</p>
</mainelement>