循环中AppendChild(1)的值添加不了,而AppendChild(0)和(2)却能添加。。。。。。..................。。。。。。。。。

OICQshenshi 2010-04-07 11:07:13
bookstore.xml:
<?xml version="1.0" encoding="utf-8"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4" old="29">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<applenote genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</applenote>
<book genre="fantasy" ISBN="2-3631-6">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.96</price>
</book>
<book genre="fantasy" ISBN="2-3631-6">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.97</price>
</book>
</bookstore>


c#文件中:

            XmlElement xe1 = xmlDoc.CreateElement(childNodeName);//创建一个节点
parentNode.AppendChild(xe1);//添加到父节点节点中
for (int i = 0; i < tmpXe.Count; i++)
{
xe1.AppendChild(tmpXe.Item(i));//将临时节点添加到新元素中
xmlDoc.Save(xmlFile);
}


只能添加Item(0)和Item(2)的值,缺没有添加到 Item(1)的值,请教为何会这样。
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
OICQshenshi 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
for (int i = tmpXe.Count-1; i>-1; i--)
试试
[/Quote]

能取出来第二个了,不过序列反掉了阿。。。
孟子E章 2010-04-07
  • 打赏
  • 举报
回复
for (int i = tmpXe.Count-1; i>-1; i--)
试试
OICQshenshi 2010-04-07
  • 打赏
  • 举报
回复
搞定了,哈哈
OICQshenshi 2010-04-07
  • 打赏
  • 举报
回复
为啥正序时添加不了Item(1)呢????????????

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧