TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mostafa gh
NA
3
597
how repeat specific tag with child after last tag XML
Jan 9 2018 7:25 AM
hi
my xml samle:
<
Y
>
<
x
>
<
PH
>
<
SQ
>
3
SQ
>
<
ND
>
4524115
ND
>
<
SN
>
545
SN
>
<
PC
>
545
PC
>
<
PG
>
54
PG
>
<
PP
>
5400
PP
>
<
PS
>
44500
PS
>
<
IS
>
0
IS
>
PH
>
<
BY
>
<
MH
>
<
MG
>
4545
MG
>
<
MP
>
25000
MP
>
<
MI
>
15000
MI
>
<
MS
>
0
MS
>
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
>
3
SQ
>
<
ND
>
4524115
ND
>
<
SN
>
545
SN
>
<
PC
>
545
PC
>
<
PG
>
54
PG
>
<
PP
>
5400
PP
>
<
PS
>
44500
PS
>
<
IS
>
0
IS
>
PH
>
<
BY
>
<
MH
>
<
MG
>
4545
MG
>
<
MP
>
25000
MP
>
<
MI
>
15000
MI
>
<
MS
>
0
MS
>
MH
>
<
MH
>
<
MG
>
123
MG
>
i want add this MH tag
<
MP
>
5000
MP
>
<
MI
>
5000
MI
>
<
MS
>
0
MS
>
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
Reply
Answers (
1
)
Pass array from client side to service side c#
how to fix Server Error in '/' Application Error??