Solved

How to update an XML document

Posted on 2011-09-25
4
175 Views
Last Modified: 2012-05-12
I have an XML document that contains images that I use to display on the page.  I need to be able to update the images in the XML document.  I have a control panel on my page that has the list of images that should be in the XML.  How do I delete the images and repopulate the XML document?  The code below allows me to get the images so now I just need to know how to delete them and replace them with the new list.
Dim xmlDoc As New XmlDocument
        xmlDoc.Load(Server.MapPath("images.xml"))

        Dim nodeList As XmlNodeList
        Dim root As XmlNode = xmlDoc.DocumentElement
        Dim img As XmlNode
        nodeList = root.SelectNodes("descendant::image")

Open in new window

0
Comment
Question by:dyarosh
  • 3
4 Comments
 
LVL 16

Accepted Solution

by:
disrupt earned 500 total points
ID: 36596481
something like so:
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("images.xml"))
Dim nodes As XmlNodeList = xmlDoc.SelectNodes("//image")
For Each node As XmlNode In nodes
	node.ParentNode.RemoveChild(node)
Next

Open in new window

0
 
LVL 16

Expert Comment

by:disrupt
ID: 36596486
you just need to add the following below to your code to delete them:
For Each node As XmlNode In nodeList
	node.ParentNode.RemoveChild(node)
Next

Open in new window

0
 
LVL 16

Assisted Solution

by:disrupt
disrupt earned 500 total points
ID: 36596496
To add just do something like so:

Dim elem As XmlElement = xmlDoc.CreateElement("image")
Dim text As XmlText = xmlDoc.CreateTextNode("Image Name")
xmlDoc.DocumentElement.AppendChild(elem)
xmlDoc.DocumentElement.LastChild.AppendChild(text)

Open in new window

0
 

Author Closing Comment

by:dyarosh
ID: 36713982
Thank you.  That did exactly what I needed.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now