Solved

How to update an XML document

Posted on 2011-09-25
4
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 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