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
Solved

How to update an XML document

Posted on 2011-09-25
4
198 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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.

790 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