Solved

Updating a single attribute element in an XML file

Posted on 2006-11-04
2
164 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

737 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