RSS Forums RSS

Problem in Removing Node from XML using Vb.net

Please support our VB.NET advertiser: DiscountASP.NET – 3 Months Free on VB.NET Web Hosting
Thread Solved
Reply
Posts: 26
Reputation: jaiprakash15 is an unknown quantity at this point 
Solved Threads: 0
jaiprakash15 jaiprakash15 is offline Offline
Light Poster

Problem in Removing Node from XML using Vb.net

  #1  
Jan 6th, 2009
Dear All..

I been working on XML for the past 2 weeks and am bit new to this concept..however i have put my effort to solve my problem..

I have suceeded in creating and appending a node to a XML file..But i have problem in Removing a node in a XML file..Please see my Code below and help me to Solve this problem..

XML file... = final.xml

<TaskDetails>
<Task>
<Name>PS0002439</Name>
<Status>Open</Status>
</Task>
<Task>
<Name>PS0002440</Name>
<Satus>Open</Satus>
</Task>
</TaskDetails>


Code to Remove Node..

Am using a button to remove the node..

Button

Private Sub BnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BnStart.Click
dim Taskid1 as string
Taskid1 = "PS0002440"
Taskid1 = Taskid1.Trim
Call XmlRemove(Taskid1)
End Sub

Function

Public Sub XmlRemove(ByVal TaskId As String)
Dim Tskid, Stats As String
Tskid = TaskId.ToString.Trim
MsgBox("in")
Dim myDoc As Xml.XmlDocument = New Xml.XmlDocument
myDoc.Load("d:\final.xml")
MsgBox("file loaded")
Dim myNode As XmlNode = myDoc.SelectSingleNode("TaskDetails\Task[Name='" & Tskid & "']")
MsgBox("Node Deleted")
Dim root As XmlNode = myDoc.DocumentElement()
root.RemoveChild(myNode)
myDoc.Save("d:\final.xml")
MsgBox("Xml File Generated")
End Sub

Please Help me..i need to remove the parend node when i pass the taskid to the function..
AddThis Social Bookmark Button
Reply With Quote  
Posts: 26
Reputation: jaiprakash15 is an unknown quantity at this point 
Solved Threads: 0
jaiprakash15 jaiprakash15 is offline Offline
Light Poster

Re: Problem in Removing Node from XML using Vb.net

  #2  
Jan 8th, 2009
Dear friends..

I have solved the Thread with slight modification in the XML file...

<?xml version="1.0" encoding="utf-8"?>
<TaskDetails>
<Task Name="PS0001234">
<Status>Start</Status>
</Task>
</TaskDetails>

Now i can delete the nodes sucessfull...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the VB.NET Forum
Views: 691 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:22 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC