XML内容如下.
<pie>
  <slice title="周一">100</slice>
  <slice title="周二">200</slice>
  <slice title="周三">300</slice>
  <slice title="周四">400</slice>
</pie>
.net如何更改"100","200"...这些值!能给出方法吗?

解决方案 »

  1.   

    SetAttribute  /   XmlElement.InnerText
      

  2.   

    [code type="C#]
    XmlDocument doc = new XmlDocument();
                doc.Load(@"D:\t.xml");            XmlNodeList nodes = doc.SelectNodes("//slice");
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["title"].Value == "周一")
                    {
                        node.InnerText = "Monday";
                    }
                }
                doc.Save(@"D:\t.xml");
    [/code]
      

  3.   

    读<?xml version="1.0" encoding="utf-8" ?>
    <Root url="Index.aspx" name="日报系统总览"  describe="日报系统">
      <Parent url="Default.aspx" name="任务管理"  describe="任务管理" >   
        <Child url="MyWork.aspx" name="我的工作台"  describe="我的工作台" />
        <Child url="OverWork.aspx" name="以完成的任务"  describe="以完成的任务" />
        <Child url="dailyPaper.aspx" name="日报"  describe="日报" />
        <Child url="weekly.aspx" name="周报"  describe="周报" />
      </Parent>
     
    </Root>using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class Left : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                XmlDataSource XmlComputer = new XmlDataSource();    //建立XmlDataSource实例
                XmlComputer.ID = "ComputerProducts";
                XmlComputer.DataFile = "XMLFile.xml";    //指定XmlDataSource来源为XML文件    
                TreeView1.DataSource = XmlComputer;    //指定xml数据            //或是您可以用下列方式声明
                //指定TreeView的数据源为XmlComputer
                //TreeView1.DataSourceID = XmlComputer.UniqueID;        
                //Page.Controls.Add(XmlComputer);            //建立根节点
                TreeNodeBinding RootBinding = new TreeNodeBinding();
                RootBinding.DataMember = "Root";    //指定RootBinding数据成员为Root节点
                RootBinding.NavigateUrlField = "url";    //指定RootBinding的NavigateUrl为url
                RootBinding.TextField = "name";        //指定TextField为name
                RootBinding.ToolTipField = "describe";    //指定ToolTipField为describe
                RootBinding.Target = "mainframe";
                //将RootBinding加入DataBindings之中
                TreeView1.DataBindings.Add(RootBinding);            //建立父节点
                TreeNodeBinding ParentBinding = new TreeNodeBinding();
                ParentBinding.DataMember = "Parent";
                ParentBinding.NavigateUrlField = "url";
                ParentBinding.TextField = "name";
                ParentBinding.ToolTipField = "describe";
                ParentBinding.Target = "mainframe";
              
                TreeView1.DataBindings.Add(ParentBinding);            //建立子节点(叶节点)
                TreeNodeBinding ChildBinding = new TreeNodeBinding();
                ChildBinding.DataMember = "Child";
                ChildBinding.NavigateUrlField = "url";
                ChildBinding.TextField = "name";
                ChildBinding.ToolTipField = "describe";
                ChildBinding.Target = "mainframe";
                TreeView1.DataBindings.Add(ChildBinding);            //Page.FindControl("Form1").Controls.Add(TreeView1);            this.TreeView1.DataBind();    //TreeView进行数据绑定            
            }
        } 
    }
      

  4.   

                XmlDocument xml = new XmlDocument();
                xml.Load(@"E:\1.xml");
                XmlNode node = xml.SelectSingleNode("//slice[text()='100']");
                node.InnerText = "1000000";
                xml.Save(@"E:\1.xml");
      

  5.   


                XmlDocument xml = new XmlDocument();
                xml.Load(@"E:\price.xml");
                XmlNode node = xml.SelectSingleNode("//pie/slice[@title=\"周一\"]");
                node.InnerText = "1000000";
                xml.Save(@"E:\price.xml");若要同时更改所有的,只需要把[]以及其中的内容去掉就行
      

  6.   


    <?xml version="1.0" encoding="GB2312" standalone="no"?>
    <学生作业列表>
      <学生 ID="1">
        <课程名称>XML语言及应用</课程名称>
        <批次>1</批次>
        <学号>20013121</学号>
        <姓名>草笛痕</姓名>
        <班级>计信(数据库)</班级>
        <作业内容><![CDATA[data]]></作业内容>
      </学生>
    </学生作业列表>
    XmlDocument doc = new XmlDocument();
                XmlElement xsinfo = doc.CreateElement("学生作业列表");
                XmlDeclaration sm = doc.CreateXmlDeclaration("1.0", "GB2312", "no");            XmlElement xs = doc.CreateElement("学生");
                xs.SetAttribute("ID", "1");            XmlElement kcmc = doc.CreateElement("课程名称");
                kcmc.AppendChild(doc.CreateTextNode("XML语言及应用"));            XmlElement pc = doc.CreateElement("批次");
                pc.AppendChild(doc.CreateTextNode("1"));            XmlElement xh = doc.CreateElement("学号");
                xh.AppendChild(doc.CreateTextNode("20013121"));            XmlElement xm = doc.CreateElement("姓名");
                xm.AppendChild(doc.CreateTextNode("草笛痕"));            XmlElement bj = doc.CreateElement("班级");//创建<班级>元素并赋值
                bj.AppendChild(doc.CreateTextNode("计信(数据库)"));            XmlElement rq = doc.CreateElement("作业内容");//创建<出生日期>元素并赋值 
                rq.AppendChild(doc.CreateCDataSection("data"));            xs.AppendChild(kcmc);
                xs.AppendChild(pc);
                xs.AppendChild(xh);
                xs.AppendChild(xm);
                xs.AppendChild(bj);
                xs.AppendChild(rq);            xsinfo.AppendChild(xs);            doc.AppendChild(sm);//将声明加入到文档中
                doc.AppendChild(xsinfo);//添加根元素            doc.Save("d:\\Student_info.xml");