Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating an XML File

Status
Not open for further replies.

tjvegter

Programmer
Aug 10, 2004
1
US
Hi,

I am creating a form in vb.net in which the user enters his info, and that info needs to be stored in an xml file. I have figured out how to create a new xml file, but I can't figure out how to update the existing xml. For instance the current xml file might look like this:

<xmlData>
<user id="12">
<userFName>firstname</userFName>
<userLName>lastname</userFName>
<userAge>age</userAge>
</user>
</xmlData>

And after a new user enters his information I would need the xml to look like this:

<xmlData>
<user id="12">
<userFName>firstname</userFName>
<userLName>lastname</userFName>
<userAge>age</userAge>
</user>
<user id="13">
<userFName>firstname</userFName>
<userLName>lastname</userFName>
<userAge>age</userAge>
</user>
</xmlData>

Anybody have any ideas? Code examples would be greatly appreciated.

Torrey
 
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("names.xml")

Dim objCurrNode, objNewNode, objNewText
Set objNewNode = objXMLDoc.createElement("name")
Set objNewText = objXMLDoc.createTextNode("John")
objNewNode.appendChild(objNewText)

Set objCurrNode = objXMLDoc.documentElement
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild
Response.write(objCurrNode.firstChild.nodeValue)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top