ASP.NET VB 添加具有removechild() 函数的按钮

发布于 2025-01-06 00:12:56 字数 3050 浏览 0 评论 0原文

我只是想知道如何在 XML 上添加具有removechild() 或replacechild() 函数的按钮。已经找这个一周了。

任何建议将不胜感激。谢谢:)

这是我的 xml 文件内容

 <?xml version="1.0" encoding="utf-8"?>
 <theNews>
 <news>
 <contents>News3 Contents</contents>
 <title>News3 Title</title>
 <pubDate>February 13, 2012</pubDate>
 </news>
 <news>
 <contents>News2 Contents</contents>
 <title>News2 Title</title>
 <pubDate>February 1, 2012</pubDate>
 </news>
 <news>
 <contents>News1 Contents</contents>
 <title>News1 Title</title>
 <pubDate>January 22, 2012</pubDate>
 </news>
 </theNews>

这是我的 News Updater 的代码

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="NewsUpdater.aspx.vb" Inherits="NewsUpdater" %>

 <%-- Add content controls here --%><asp:Content ID="Content1" runat="server" 
contentplaceholderid="ContentPlaceHolder1">

        <p>
            &nbsp;</p>
        <table align="center" style="width: 63%">
            <tr>
                <td align=center>
                    <div>
    <h3>News Title</h3>
    <asp:TextBox runat="server" ID="txtTitle" Width="308px"></asp:TextBox>
                        <br />
    <h3>News Content</h3>
    <asp:TextBox runat="server" ID="txtContents" TextMode="MultiLine" Height="119px" Width="513px"></asp:TextBox>


                        <br />

                        <br />
                        <asp:Button ID="Button1" runat="server" Text="Update News" />
</div></td>
            </tr>
        </table>
        <p>
            <br />
        </p>

这是 NewsUpdater 按钮背后的代码

 Partial Class NewsUpdater
 Inherits System.Web.UI.Page

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

我想添加另一个按钮,该按钮具有删除或替换 xml 的最后/最新条目的功能。

I just want to know how to add a button that has a removechild() or replacechild() function on my XML. Been searching for this for a week now.

Any suggestions would be greatly appreciated. Thanks :)

This is my xml file content

 <?xml version="1.0" encoding="utf-8"?>
 <theNews>
 <news>
 <contents>News3 Contents</contents>
 <title>News3 Title</title>
 <pubDate>February 13, 2012</pubDate>
 </news>
 <news>
 <contents>News2 Contents</contents>
 <title>News2 Title</title>
 <pubDate>February 1, 2012</pubDate>
 </news>
 <news>
 <contents>News1 Contents</contents>
 <title>News1 Title</title>
 <pubDate>January 22, 2012</pubDate>
 </news>
 </theNews>

This is the code for my News Updater

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="NewsUpdater.aspx.vb" Inherits="NewsUpdater" %>

 <%-- Add content controls here --%><asp:Content ID="Content1" runat="server" 
contentplaceholderid="ContentPlaceHolder1">

        <p>
             </p>
        <table align="center" style="width: 63%">
            <tr>
                <td align=center>
                    <div>
    <h3>News Title</h3>
    <asp:TextBox runat="server" ID="txtTitle" Width="308px"></asp:TextBox>
                        <br />
    <h3>News Content</h3>
    <asp:TextBox runat="server" ID="txtContents" TextMode="MultiLine" Height="119px" Width="513px"></asp:TextBox>


                        <br />

                        <br />
                        <asp:Button ID="Button1" runat="server" Text="Update News" />
</div></td>
            </tr>
        </table>
        <p>
            <br />
        </p>

And this is the code behind the NewsUpdater button

 Partial Class NewsUpdater
 Inherits System.Web.UI.Page

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

I want to add another button that has a function of remove or replace the last/latest entry to the xml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2025-01-13 00:12:56

那么这条线会做你想要的吗?

xmlFile.DocumentElement.RemoveChild(xmlFile.DocumentElement.LastChild)
xmlFile.DocumentElement.AppendChild(your_replacement_element)

So would this line do what you want?

xmlFile.DocumentElement.RemoveChild(xmlFile.DocumentElement.LastChild)
xmlFile.DocumentElement.AppendChild(your_replacement_element)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文