|
-
May 4th, 2006, 12:47 AM
#1
Thread Starter
Junior Member
appending data to an XML file
Hi can someone help me with appending data to an XML file.
I want to save some data to a XML file which is done by the following code.
VB Code:
Private Sub Command47_Click()
CommonDialog1.ShowSave
NewFileSave = CommonDialog1.FileName
MsgBox NewFileSave
xml.SaveXml NewFileSave
MsgBox "Saved"
CancelButton:
Exit Sub
End Sub
Now if i open an existing file and save my data in that file the original data is lost.
How to append the data to the existing XML file ???
Amit
-
May 8th, 2006, 06:08 AM
#2
Thread Starter
Junior Member
Re: appending data to an XML file
Urgent help required as i am stuck with this problem.
I am storing some data in the buffer through input from a GUI and am saving the data using the code mentioned in the 1st post to a new XML file but i am not able to append the same data stored in the buffer to an existing XML file.
Can anyone help me out ??????
Thanks,
Amit
-
May 8th, 2006, 06:13 AM
#3
Re: appending data to an XML file
Here is the code to append xml:
VB Code:
Sub Append_XML_Element(oXMLfile As String)
' Requires msxml.dll (Go to Project --> References and and choose Microsoft XML version 2.0, or whatever the
' current version you have installed)
Dim objDom As New MSXML2.DOMDocument26
Dim objRootElem As IXMLDOMElement
Dim objSubRootElem As IXMLDOMElement
Dim objMemberElem As IXMLDOMElement
'Load xml files
objDom.async = False
objDom.Load oXMLfile
' Loads root element
Set objRootElem = objDom.documentElement
' Creates sub root element
Set objSubRootElem = objDom.createElement("MySubRootElement")
objRootElem.appendChild objSubRootElem
' Creates Error Date & Time element
Set objMemberElem = objDom.createElement("DateTime")
objSubRootElem.appendChild objMemberElem
objMemberElem.Text = Format(Now, "DD-MMM-YYYY hh:mm:ss")
' Saves XML data to disk.
objDom.save oXMLfile
ExitHere:
Err.Clear
Set objDom = Nothing
End Sub
-
May 8th, 2006, 06:13 AM
#4
Re: appending data to an XML file
Please modify as per your need.
-
May 9th, 2006, 02:45 AM
#5
Thread Starter
Junior Member
Re: appending data to an XML file
Thanks for the hep but what i am going to append is not predefined and is only entered by the user using a gui and i need to save the enteries made by the user to the exisiting XML file
Amit
-
May 9th, 2006, 03:33 AM
#6
Re: appending data to an XML file
No probs! Change the field name and its value in the above code as per your requirement.
Are you appending the data or going to edit existing data?
 Originally Posted by kamitsin
Thanks for the hep but what i am going to append is not predefined and is only entered by the user using a gui and i need to save the enteries made by the user to the exisiting XML file
For any data there will be a constant field name and in run time the user will enter the value for that field right. So, if you have filed "Student Name" and in run time the user is entering the name of the student "Amit" in a text box (Let's say name of the text box txtStudent) then in above code you need to change as:
VB Code:
' Creates Student Name element
Set objMemberElem = objDom.createElement("StudentName")
objSubRootElem.appendChild objMemberElem
objMemberElem.Text = txtStudent.Text
Everytime you need to use this code to append a new node on xml.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|