hi
my xml samle:
- <Y>
- <x>
- <PH>
- <SQ>3SQ>
- <ND>4524115ND>
- <SN>545SN>
- <PC>545PC>
- <PG>54PG>
- <PP>5400PP>
- <PS>44500PS>
- <IS>0IS>
- PH>
- <BY>
- <MH>
- <MG>4545MG>
- <MP>25000MP>
- <MI>15000MI>
- <MS>0MS>
- MH>
- BY>
- x>
- Y>
i have create text box for each tag and i have one button (save) to create X tag and chiled.
i want add new button "add MH" to add MH tag and child ( MG,MP,MI,MS) after last MH tag
i wang after click button update xml sample this:
- <Y>
- <x>
- <PH>
- <SQ>3SQ>
- <ND>4524115ND>
- <SN>545SN>
- <PC>545PC>
- <PG>54PG>
- <PP>5400PP>
- <PS>44500PS>
- <IS>0IS>
- PH>
- <BY>
- <MH>
- <MG>4545MG>
- <MP>25000MP>
- <MI>15000MI>
- <MS>0MS>
- MH>
- <MH>
- <MG>123MG> i want add this MH tag
- <MP>5000MP>
- <MI>5000MI>
- <MS>0MS>
- MH>
- BY>
- x>
- Y>
my code for Button Save is:
- private void button1_Click(object sender, EventArgs e){
- XmlNode customernode = xmldoc.CreateNode(XmlNodeType.Element, "x", null);
- XmlNode tartibnode = xmldoc.CreateNode(XmlNodeType.Element, "SQ", null);
- XmlNode datevisitnode = xmldoc.CreateNode(XmlNodeType.Element, "ND", null);
- XmlNode bimenode = xmldoc.CreateNode(XmlNodeType.Element, "SN", null);
- XmlNode nezamnode = xmldoc.CreateNode(XmlNodeType.Element, "PC", null);
- XmlNode pezeshknode = xmldoc.CreateNode(XmlNodeType.Element, "PG", null);
- XmlNode mablaghkolnode = xmldoc.CreateNode(XmlNodeType.Element, "PP", null);
- XmlNode mablaghbimarnode = xmldoc.CreateNode(XmlNodeType.Element, "PS", null);
- XmlNode mablaghbimenode = xmldoc.CreateNode(XmlNodeType.Element, "IS", null);
- XmlNode khedmatnode = xmldoc.CreateNode(XmlNodeType.Element, "MG", null);
- XmlNode sahmekolnode = xmldoc.CreateNode(XmlNodeType.Element, "MP", null);
- XmlNode sahmebimenode = xmldoc.CreateNode(XmlNodeType.Element, "MI", null);
- XmlNode sahmebimarnode = xmldoc.CreateNode(XmlNodeType.Element, "MS", null);
- XmlNode tagkolnode = xmldoc.CreateNode(XmlNodeType.Element, "PH", null);
- XmlNode tagkhedmatnode = xmldoc.CreateNode(XmlNodeType.Element, "MH", null);
- XmlNode tagbynode = xmldoc.CreateNode(XmlNodeType.Element, "BY", null);
-
- tartibnode.InnerText = txtsq.Text;
- datevisitnode.InnerText = txtnd.Text;
- bimenode.InnerText = txtsn.Text;
- nezamnode.InnerText = txtpc.Text;
- pezeshknode.InnerText = txtpg.Text;
- mablaghkolnode.InnerText = txtpp.Text;
- mablaghbimarnode.InnerText = txtps.Text;
- mablaghbimenode.InnerText = txtis.Text;
- khedmatnode.InnerText = txtmg.Text;
- sahmekolnode.InnerText = txtmp.Text;
- sahmebimenode.InnerText = txtmi.Text;
- sahmebimarnode.InnerText = txtms.Text;
-
- tagkolnode.AppendChild(tartibnode);
- tagkolnode.AppendChild(datevisitnode);
- tagkolnode.AppendChild(bimenode);
- tagkolnode.AppendChild(nezamnode);
- tagkolnode.AppendChild(pezeshknode);
- tagkolnode.AppendChild(mablaghkolnode);
- tagkolnode.AppendChild(mablaghbimarnode);
- tagkolnode.AppendChild(mablaghbimenode);
-
- tagkhedmatnode.AppendChild(khedmatnode);
- tagkhedmatnode.AppendChild(sahmekolnode);
- tagkhedmatnode.AppendChild(sahmebimenode);
- tagkhedmatnode.AppendChild(sahmebimarnode);
-
- tagbynode.AppendChild(tagkhedmatnode);
- customernode.AppendChild(tagkolnode);
- customernode.AppendChild(tagbynode);
- rootnote.AppendChild(customernode);
-
- xmldoc.Save(xmlpath); }
for Button update this code but not work:
- private void button2_Click(object sender, EventArgs e)
- {
-
- xmldoc.Load(xmlpath);
- rootnote = xmldoc.DocumentElement;
-
- XmlNode khedmatnode = xmldoc.CreateNode(XmlNodeType.Element, "MG", null);
- XmlNode sahmekolnode = xmldoc.CreateNode(XmlNodeType.Element, "MP", null);
- XmlNode sahmebimenode = xmldoc.CreateNode(XmlNodeType.Element, "MI", null);
- XmlNode sahmebimarnode = xmldoc.CreateNode(XmlNodeType.Element, "MS", null);
- XmlNode tagkhedmatnode = xmldoc.CreateNode(XmlNodeType.Element, "MH", null);
- XmlNode tagbynode = xmldoc.CreateNode(XmlNodeType.Element, "BY", null);
-
-
- khedmatnode.InnerText = txtmg.Text;
- sahmekolnode.InnerText = txtmp.Text;
- sahmebimenode.InnerText = txtmi.Text;
- sahmebimarnode.InnerText = txtms.Text;
-
- tagkhedmatnode.AppendChild(khedmatnode);
- tagkhedmatnode.AppendChild(sahmekolnode);
- tagkhedmatnode.AppendChild(sahmebimenode);
- tagkhedmatnode.AppendChild(sahmebimarnode);
-
- tagbynode.AppendChild(tagkhedmatnode);
-
- tagbynode.InsertAfter(tagkhedmatnode , tagkhedmatnode);
-
-
-
- xmldoc.Save(xmlpath);
- }
tank you