开发者

I need to perform add, delete, update, read data using xml. this code has probs? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
    private const string filename = "output.xml";

    /// <summary>
    /// Create file code
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        XmlTextWriter newXmlFile = new XmlTextWriter(filename,System.Text.Encoding.Default);    
        newXmlFile.WriteStartDocument();            
        newXmlFile.WriteStartElement("Begin","");
        newXmlFile.WriteStartElement("One","");
        newXmlFile.WriteFullEndElement();
        newXmlFile.WriteEndElement();
        newXmlFile.Flush();
        newXmlFile.Close();
    }
    /// <summary>
    /// Insert New code
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>

    private void button2_Click(object sender, EventArgs e)
    {
       XmlDocument XMLDom = new XmlDocument();
        XMLDom.Load(filename);
        XmlNode newXMLNode = XMLDom.SelectSingleNode("Begin");
        XmlNode childN开发者_运维问答ode = XMLDom.CreateNode(XmlNodeType.Element,"One","");
        XmlAttribute newAttribute = XMLDom.CreateAttribute("name","sree","");
        childNode.Attributes.Append(newAttribute);
        newXMLNode.AppendChild(childNode);
    }
}

}


Look at Linq to XML and the System.Xml namespace.


Like Oded says: Linq to XML should get you there...

These classes are the important ones:

  • XDocument
    • `var doc = XDocument.Load("myfilepath")
  • XElement
  • XAttribute
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜