Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 1st, 2007, 02:46 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help deleting multiple XML nodes

Sorry for the bother, but I did a search of the forums and did not find an exact solution to my problem. Google wasn't much help either.

I need to loop through an XML structure and delete multiple nodes where an attribute, EnclosureID="1".

The problem with my current code is that the first element is deleted but not the rest. I am brand new to XML so I am obviously doing something wrong. I will post my code and part of the XML below.

I would really appreciate some help with this.

Partial XML:
<?xml version="1.0" encoding="utf-8"?>

<EnclosureSeriesLinks>
  <EnclosureSeries EnclosureID="1" SeriesID="1" SeriesName="0000 Frameless Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="4" SeriesName="6000 Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="6" SeriesName="9000 Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="7" SeriesName="F000 Frameless Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="10" SeriesName="P000 Provincial Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="11" SeriesName="Q000 Frameless Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="12" SeriesName="Steam Series" />
  <EnclosureSeries EnclosureID="2" SeriesID="1" SeriesName="0000 Frameless Series" />
  <EnclosureSeries EnclosureID="2" SeriesID="4" SeriesName="6000 Series" />
</EnclosureSeriesLinks>


Current Code:
Dim EnclosureSeries As XmlDocument = New XmlDocument
            Dim esindex As Integer = 0
            EnclosureSeries.Load("c:\csd2007data\enclosureseri es.xml")
            For Each myNode As XmlNode In EnclosureSeries.DocumentElement.ChildNodes
                If myNode.Attributes("EnclosureID").Value.ToString = sdeleted Then
                    myNode.ParentNode.RemoveChild(EnclosureSeries.Docu mentElement.ChildNodes(esindex))
                    'MsgBox(myNode.Attributes("EnclosureID").Value.ToS tring)
                End If
                esindex += 1
            Next
            EnclosureSeries.Save("c:\csd2007data\enclosureseri es.xml")



Only the very first record is deleted and I want to delete all items where EnclosureID="1".

The resulting XML is
<EnclosureSeries EnclosureID="1" SeriesID="4" SeriesName="6000 Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="6" SeriesName="9000 Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="7" SeriesName="F000 Frameless Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="10" SeriesName="P000 Provincial Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="11" SeriesName="Q000 Frameless Series" />
  <EnclosureSeries EnclosureID="1" SeriesID="12" SeriesName="Steam Series" />
  <EnclosureSeries EnclosureID="2" SeriesID="1" SeriesName="0000 Frameless Series" />
  <EnclosureSeries EnclosureID="2" SeriesID="4" SeriesName="6000 Series" />
</EnclosureSeriesLinks>

Reply With Quote
  #2 (permalink)  
Old October 1st, 2007, 04:45 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind I figured it out. The code snippet is below, in case anyone else needs it:

Dim doc As XmlDocument = New XmlDocument
        doc.Load("c:\csd2007data\enclosureseries.xml")
        Dim nodelist As XmlNodeList
        Dim root As XmlNode = doc.DocumentElement
        nodelist = root.SelectNodes("//EnclosureSeries[@EnclosureID=1]")
        For Each es As XmlNode In nodelist
            es.ParentNode.RemoveChild(es)
        Next
        doc.Save("c:\csd2007data\enclosureseries.xml")

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting multiple rows in data view or grid deepakbachelor SQL Server 2005 1 December 7th, 2007 02:19 PM
TreeView deleting Nodes Apocolypse2005 Beginning VB 6 3 July 11th, 2007 04:16 AM
*solved* applying same template to multiple nodes Brian Campbell XSLT 3 October 13th, 2006 06:56 PM
Deleting multiple records from the same table jscrogg Beginning VB 6 3 June 12th, 2006 05:30 AM
Display nodes from xml nambati XSLT 2 September 17th, 2004 07:57 AM



All times are GMT -4. The time now is 12:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.