2012-02-15 3 views
0

XML에 removechild() 또는 replacechild() 함수가있는 단추를 추가하는 방법을 알고 싶습니다. 1 주일 동안 이걸 찾고 있었어.removechild() 함수가있는 ASP.NET VB 추가 단추

의견을 보내 주시면 대단히 감사하겠습니다. 감사합니다 :)이

내 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> 

이 내 뉴스 업데이

<%@ 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에 제거하거나 바꾸는 기능이있는 다른 버튼을 추가하고 싶습니다.

+0

XML 서버 측 또는 클라이언트 측은 어디에 있습니까? 클라이언트 측, jQuery를 사용하고 있다면 괜찮습니까? – CompanyDroneFromSector7G

+0

나는 내 게시물을 이미 업데이트했습니다. 그것을 확인하시기 바랍니다. 나는 서버쪽에있다 –

+0

고마워. "마지막/최신 항목"은 어떻게 정의합니까? 예 : 루트 노드의 마지막 자식입니까? – CompanyDroneFromSector7G

답변

0

그럼이 라인이 원하는대로 할 수 있습니까?

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

이 될 lastchild를 제거하거나 바꿀 수 있습니까? 코드를 복사하여 붙여 넣고 위의 코드에 추가해야합니까? 또는 그것을 수정해야합니까? 이 단추를 추가해야합니까? 죄송합니다. 나는 이것에 처음이다, 너는이 가이드로 나를 크게 도와 줄 것이다. –

+0

probs :) 만약 당신이 당신이 당신의 코스로 your_replacement_element를 바꾸는 것 - 당신이 대체를하고 싶다면 위의 코드를 붙여 넣는다. 충분히. 그렇지 않다면 아마 오해했을 것입니다. 단지 알려주세요. – CompanyDroneFromSector7G

+0

감사합니다. 너는 나를 많이 도왔다. :) –