ASP.NET如何在xml上使用ReplaceChild

时间:2012-02-12 13:51:11

标签: asp.net xml replace

如何在xml上使用replaceChild?我正在使用VB。

如何在我的代码中插入replaceChild .......

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim xmlFile As New System.Xml.XmlDocument()
    xmlFile.Load("D:\My Documents\PresentableII\NewsContent.xml")

    Dim theNewsTag As System.Xml.XmlElement = xmlFile.CreateElement("news")
    Dim theTitleTag As System.Xml.XmlElement = xmlFile.CreateElement("title")
    Dim theContentsTag As System.Xml.XmlElement = xmlFile.CreateElement("contents")

    Dim theTitleText As System.Xml.XmlText = xmlFile.CreateTextNode(txtTitle.Text)
    Dim theContentsText As System.Xml.XmlText = xmlFile.CreateTextNode(txtContents.Text)

    theTitleTag.PrependChild(theTitleText)
    theContentsTag.PrependChild(theContentsText)

    theNewsTag.PrependChild(theTitleTag)
    theNewsTag.PrependChild(theContentsTag)

    xmlFile.DocumentElement.PrependChild(theNewsTag)
    xmlFile.Save("D:\My Documents\PresentableII\NewsContent.xml")

    Response.Redirect("NewsFrame.aspx")

End Sub    

0 个答案:

没有答案