[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to update an XML document

Posted on 2011-09-25
4
Medium Priority
?
224 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 2000 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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