我写了一段代码,大家看看是否正确:/----------------
'首先获得QueryString的值,此值为xml文件物理地址
Dim strFile As String = (Request.QueryString("File")) '使用Xml DOM方式打开xml文件,装入内存
'首先定义文件流对象
Dim objDom As New XmlDocument()
Dim objFile As New FileStream(strFile, FileMode.Open)
objDom.Load(objFile) '打开文件
'定义写入的根节点
Dim nodRoot As XmlNode = objDom.DocumentElement("Family")
'开始写入元素
Try
  Dim nodMember As XmlElement = objDom.CreateElement("Member")
  nodMember.SetAttribute("CallTitle", Title.Text)
  nodRoot.AppendChild(nodMember)
  '再次定义根节点
  nodRoot = objDom.DocumentElement("Member")
  '写入Member的子节点
  '建立名称
  Dim nameElement As XmlElement = objDom.CreateElement("Name")
  nameElement.Value = Name.Text
  nodRoot.AppendChild(nameElement)
  '建立出生
  Dim birthElement As XmlElement = objDom.CreateElement("Birth")
  birthElement.Value = Birth.Text
  nodRoot.AppendChild(birthElement)
  '建立政治面貌
  Dim poilticElement As XmlElement = objDom.CreateElement("Poiltic")
  poilticElement.Value = Poiltic.Text
  nodRoot.AppendChild(poilticElement)
  '建立职务
  Dim dutyElement As XmlElement = objDom.CreateElement("Duty")
  dutyElement.Value = Duty.Text
  nodRoot.AppendChild(dutyElement)  '保存文件
  objDom.Save(strFile)
  '关闭文件
  objFile.Close()Catch objErr As Exception  ShowMessage.Visible = True
  ShowMessage.Text = "写入xml文件错误,文件地址:" & strFile & "错误内容:" & objErr.Message & objErr.Source
  objFile.Close()
  Exit SubEnd Try
/---------------------------
请大家看看有没有错误,谢谢!

解决方案 »

  1.   

    XmlDocument xmlDoc=new XmlDocument();
                xmlDoc.LoadXml("<Root><Family></Family></Root>");
                XmlNode node=xmlDoc.SelectSingleNode("/Root/Family");
                node.InnerXml="<Member CallTitle=\"XXX\"><Name>XXX</Name><Birth>XXX</Birth><Poiltic>XXX</Poiltic><Duty>XXX</Duty></Member>";
                txtOut.Text=xmlDoc.InnerXml.ToString();
                //xmlDoc.Save("younamer.xml");
      

  2.   

    XmlNode AppendParameterXmlNode=FParameterXmlDoc.CreateElement("add"); //增加一个参数接点XmlAttribute InsertKey=FParameterXmlDoc.CreateAttribute("key"); //在结点中插入key的属性,用来记录年份
    InsertKey.InnerText=ParameterName; //给属性key赋值
    AppendParameterXmlNode.Attributes.Append(InsertKey); //将指定的属性插入集合

    XmlAttribute InsertValue=FParameterXmlDoc.CreateAttribute("value"); //在结点中插入value的属性,用来记录年份
    InsertValue.InnerText=ParameterValue; //给属性value赋值
    AppendParameterXmlNode.Attributes.Append(InsertValue); //将指定的属性插入集合

    ParameterNode.AppendChild(AppendParameterXmlNode); //将接点插入参数表中 
    该程序添加了1个接点“add”,该接点有2个属性“key”、“value”。
    最后将这个接点添加到“AppendParameterXmlNode”接点下面。
      

  3.   

    哦。你不要管属性后面的注释说属性是用来放什么的,因为这里都是说“用来记录年份”,其实是我忘记改了。“key”是要存放的参数名,“value”是存放的该参数的数值。
      

  4.   

    参考:
    http://expert.csdn.net/Expert/topic/1238/1238415.xml?temp=.3332636
      

  5.   

    感觉要对xml编辑应该是有专用的一套方法。
    我的笨办法是读取文件,从新生成同名的xml