在C#中,如何在XML中增加多个节点,但节点名称相同?<?xml version="1.0"?>
<IA_CHIPS_TESTED>
  <HEADER>
    <DATE>210-10-1</DATE>
    <TIME>09:32:09</TIME>
    <OPERATOR>costvminsk</OPERATOR>
  </HEADER>
  <CHIP>
    <SN>12312354</SN>
    <STBSN>12312313123123</STBSN>
  </CHIP>
</IA_CHIPS_TESTED>如何增加多个
<CHIP>
    <SN>12312354</SN>
    <STBSN>12312313123123</STBSN>
  </CHIP>请指教!

解决方案 »

  1.   

    XmlElement xe1=xmlDoc.CreateElement("");  
    XmlElement xesub1=xmlDoc.CreateElement("");  
    xesub1.InnerText="";  
    public void Insert(string path, string node, string element, string attribute, string value)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(path);
                    XmlNode xn = doc.SelectSingleNode(node);
                    if (element.Equals(""))
                    {
                        if (!attribute.Equals(""))
                        {
                            XmlElement xe = (XmlElement)xn;
                            xe.SetAttribute(attribute, value);
                        }
                    }
                    else
                    {
                        XmlElement xe = doc.CreateElement(element);
                        if (attribute.Equals(""))
                        {
                            xe.InnerText = value;
                        }
                        else
                        {
                            xe.SetAttribute(attribute, value);
                        }
                        xn.AppendChild(xe);
                    }
                    doc.Save(path);
                }
                catch { }
            }