Changing an element in an XML file

  • Thread starter Thread starter Miguel
  • Start date Start date
Miguel said:
Hi,

How do you change just the element's value in an existing xml file

Thanks
Nikron

dim xpathdoc as xpathdocument
dim xmlnav as xpathnavigator
dim xmlni as xpathnodeiterator
xpathdoc = new xpathdocument("X:\yourpath\yourfile.xml")
xmlnav=xpathdoc.createnavigator()
xmlni=xmlnav.select("customers/products/telephone") <- this is a path
you want to navigate to. you can use a [@Type="acustomer"] to filter for
the type attribute (e.g. set to acustomer)

while(xmlni.movenext())
'do whatever you want with
xmlni.current.value
end while

wrote this quickly, but should work.
have fun
tomi
 
Tamas said:
Miguel said:
Hi,

How do you change just the element's value in an existing xml file

Thanks
Nikron

dim xpathdoc as xpathdocument
dim xmlnav as xpathnavigator
dim xmlni as xpathnodeiterator
xpathdoc = new xpathdocument("X:\yourpath\yourfile.xml")
xmlnav=xpathdoc.createnavigator()
xmlni=xmlnav.select("customers/products/telephone") <- this is a path
you want to navigate to. you can use a [@Type="acustomer"] to filter for
the type attribute (e.g. set to acustomer)

while(xmlni.movenext())
'do whatever you want with
xmlni.current.value
end while

wrote this quickly, but should work.
have fun
tomi
Sorry Tamas,
I am really new to XML and don't quite understand

This is what my xml file looks like
<User>
<UserID>2</UserID>
<NNDBranchID>1</NNDBranchID>
<EmployeeNumber></EmployeeNumber>
<UserProfile></UserProfile>
<FirstName></FirstName>
<Surname></Surname>
<Cell></Cell>
<EMail></EMail>
</User>
etc.

All I want to do is basically change the values inside userid,
nndbranchid etc.
 
Another way is to simply modity the node's inner text and save the xml
file.

(The following code is NOT tested!!)

dim xmldocument as new xmldocument
dim xmlnode as xmlnode

xmldocument.load(pathtofile)
xmlnode = xmldocument.selectsinglenode("/User/UserID")
xmlnode.innertext = "some new value"
xmldocument.save(pathtofile)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top