我将节点插入xml文件时出现问题 [英] problem when I insert node to my xml file
本文介绍了我将节点插入xml文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好:)
我有这个xml文件:
hi all :)
I have this xml file:
<categories>
<itemdetails>
<item>
<text>first</text>
<categoryid>1</categoryid>
</item>
<item>
<text>Other</text>
<categoryid>2</categoryid>
</item>
</itemdetails>
<setting>
<verticaldistance>50</verticaldistance>
<itemcolour>666666</itemcolour>
<itemrollovercolour>000000</itemrollovercolour>
</setting>
</categories>
我用这种方式插入一个新节点,我知道这是一个旧节点:
and I use this way to insert a new node, I know it''s an old one:
DataSet objDataSet = new DataSet();
objDataSet.ReadXml(Server.MapPath("~/" + RadComboBox1.SelectedValue + "/c.xml"));
DataTable objTable = null;
DataRow objNewRow = null;
objTable = objDataSet.Tables["item"];
objNewRow = objTable.NewRow();
objNewRow["text"] = RadTextBox1.Text;
Random _random = new Random();
int _intrandom = _random.Next(0, 999999999);
objNewRow["categoryID"] = _intrandom;
objTable.Rows.Add(objNewRow);
objDataSet.WriteXml(Server.MapPath("~/" + RadComboBox1.SelectedValue + "/c.xml"));
RadTextBox1.Text = "";
但从< itemdetails>插入的节点节点
像这样:
but the node inserted out of <itemdetails> node
like this:
<categories>
<itemdetails>
<item>
<text>first</text>
<categoryid>1</categoryid>
</item>
<item>
<text>Other</text>
<categoryid>2</categoryid>
</item>
</itemdetails>
<item>
<text>NewNode</text>
<categoryid>whatever</categoryid>
</item>
<setting>
<verticaldistance>50</verticaldistance>
<itemcolour>666666</itemcolour>
<itemrollovercolour>000000</itemrollovercolour>
</setting>
</categories>
如何将其插入正确的位置,任何人都可以帮助我?
how can I insert it to the right place, any one help me ?
推荐答案
尝试一下
objTable = objDataSet.Tables["itemdetails"];
这篇关于我将节点插入xml文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文