Solved

Updating a single attribute element in an XML file

Posted on 2006-11-04
2
165 Views
Last Modified: 2013-11-19
Hi there, given the below xml file

how can I amend xxxxx?

<?xml version="1.0" encoding="utf-8" ?>
<values>
      <setting attribute = "user_last_logged_on" value="xxxxx"></setting>
</values>
0
Comment
Question by:DavidGreenfield
[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
2 Comments
 

Author Comment

by:DavidGreenfield
ID: 17874681
I have changed the xml format to :

<?xml version="1.0" encoding="utf-8" ?>
<values>
      <setting attribute = "user_last_logged_on">
            <user>xxxxx</user>
      </setting>
</values>

and the code so far is:

        Dim persist_xml_nodelist As XmlNodeList
        Dim persist_xml_doc = New XmlDocument()
        Dim persist_xml_node As XmlNode

        persist_xml_doc.Load("persisted.xml")
        persist_xml_nodelist = persist_xml_doc.SelectNodes("/values/setting[@attribute='user_last_logged_on']/user")
        For Each persist_xml_node In persist_xml_nodelist
            persist_xml_node.InnerText = cbo_Username.Text
        Next
        persist_xml_doc.Save("persisted.xml")
        Debug.Print(persist_xml_doc.InnerXml())

the debug print shows the xml updated correctly.  But the xml when I go to view it - it hasn't changed.  So something seems to be going wrong on saving :oS

Thanks in advance
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 500 total points
ID: 17875979
Maybe the persisted.xml is opened or is readonly .... try deleting this file and use the save method with a full path to the file like ("C:\Persisted.xml")
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

688 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