我是xml的初学者,我简单写了一个xml文件:
<?xml version="1.0" encoding="utf-8" ?> 
 <MyCalendar>
   <Event>
     <ShortDesc>Concert at Riverfrom</ShortDesc>
     <DetailDesc>4th of July celebration .Bring stand and a jacket</DetailDesc>
     <EventData>2004/09/13</EventData> 
     <StartTime>9:30PM</StartTime>
     <EndTime>11:0PM</EndTime>
   </Event>   
    <Event>
     <ShortDesc>CCT Rehearsal - Brigadoon</ShortDesc>
     <DetailDesc>Community Theatre orchestra rehearsal - bring mutes.</DetailDesc>
     <EventData>2004/09/14</EventData> 
     <StartTime>3:30PM</StartTime>
     <EndTime>6:30PM</EndTime>
   </Event>
</MyCalendar>                       
我想网此文件里写数据!  求响应的代码!最好是vb.net的!

解决方案 »

  1.   

    你怎么知道别人是男的??
    参考 xmldocument 类
      

  2.   

    Option Explicit
    Option StrictImports System
    Imports System.IO
    Imports System.XmlPublic Class Sample
        
        Public Shared Sub Main()
            
            Dim doc As New XmlDocument()
            doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                        "<title>Pride And Prejudice</title>" & _
                        "</book>")
            
            Dim root As XmlNode = doc.DocumentElement
            
            'Create a new node.
            Dim elem As XmlElement = doc.CreateElement("price")
            elem.InnerText = "19.95"
            
            'Add the node to the document.
            root.AppendChild(elem)
            
            Console.WriteLine("Display the modified XML...")
            doc.Save(Console.Out)
        End Sub 'Main 
    End Class 'Sample
      

  3.   

    C#版本:
    private void AddFormAttribute(int templateID, string templateName, ref XmlDocument Doc)
    {
    XmlNode Root = Doc.DocumentElement; XmlNode NodeForm = Root.SelectSingleNode("descendant-or-self::Form[attribute::FormID]");
    if ( NodeForm != null )
    {
    XmlAttribute attr1 = Doc.CreateAttribute("TemplateID");
    attr1.Value = templateID.ToString();
    XmlAttribute attr2 = Doc.CreateAttribute("TemplateName");
    attr2.Value = templateName;
    NodeForm.Attributes.Append(attr1);
    NodeForm.Attributes.Append(attr2);
    }
    }private void ModifyFormAttribute(string templateName, ref XmlDocument Doc)
    {
    XmlElement Root = Doc.DocumentElement; XmlNode NodeForm = Root.SelectSingleNode("descendant-or-self::Form[attribute::FormID]");
    if ( NodeForm != null )
    {
    NodeForm.Attributes["TemplateName"].Value = templateName;
    }
    }
      

  4.   

    Dim pathToXmlDoc As String = "a.Xml"
     Dim myStream As New System.IO.FileStream(pathToXmlDoc, System.IO.FileMode.Open)
     Dim myDocument As New System.Xml.XmlDocument
        myDocument.Load(myStream)
        myDocument.DocumentElement.SelectSingleNode(节点).InnerText = "值"
        myStream.Close()
        myDocument.Save(pathToXmlDoc)