Solved

How to update an XML document

Posted on 2011-09-25
4
192 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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