kingpin123
Technical User
Hell all
The reason why I am writing is because I am having trouble with appending information into my XML file and I thought that maybe someone could help me out.
What I would like is to have the new information inserted at the top of my XML file and not at the bottom. I was reading about prependChild but I am not getting it to work. Can you help me out.
This a function that I call in my asp code that appends information into an XML file.
<%
addContact "c:\projects\xml\xml","contact.xml"
If err.number <> 0 then Response.write("Errors occurred while saving your form submission.") Else Response.write("Your form submission has been saved.")
Function addContact(strXMLFilePath, strFileName)
Dim objDom
Dim objRoot
Dim objRecord
Dim objField
Dim objFieldValue
Dim objattID
Dim objattTabOrder
Dim objPI
Dim blnFileExists
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
blnFileExists = objDom.Load(strXMLFilePath & "\" & strFileName)
If blnFileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("users")
objDom.appendChild objRoot
End If
'Create the new container element for the new record.
Set objRecord = objDom.createElement("profile")
objRoot.appendChild objRecord 'I think that over here I should write objRoot.prependChild obijRecord. But I am getting an error
For x = 1 To Request.Form.Count
If instr(1,Request.Form.Key(x),"btn") = 0 Then
'Create an element, "field".
Set objField = objDom.createElement(Request.Form.Key(x))
'Create a new element, "field_value".
Set objFieldValue = objDom.createElement(Request.Form.Key(x))
'Set the value of the field_value element equal to the value of the current field in the Form Collection.
objFieldValue.Text = Request.Form(x)
'Append the field element as a child of the new record container element, contact.
objRecord.appendChild objField
'Append the field_value element as a child of the field element.
objField.appendChild objFieldValue
End If
Next
If blnFileExists = False then 'Create the xml processing instruction.
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
'Append the processing instruction to the XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
End If
'Save the XML document.
objDom.save strXMLFilePath & "\" & strFileName
'Release all of your object references.
Set objDom = Nothing
Set objRoot = Nothing
Set objRecord = Nothing
Set objField = Nothing
Set objFieldValue = Nothing
Set objattID = Nothing
Set objattTabOrder = Nothing
Set objPI = Nothing
End Function
%>
Thank-you indvance
The reason why I am writing is because I am having trouble with appending information into my XML file and I thought that maybe someone could help me out.
What I would like is to have the new information inserted at the top of my XML file and not at the bottom. I was reading about prependChild but I am not getting it to work. Can you help me out.
This a function that I call in my asp code that appends information into an XML file.
<%
addContact "c:\projects\xml\xml","contact.xml"
If err.number <> 0 then Response.write("Errors occurred while saving your form submission.") Else Response.write("Your form submission has been saved.")
Function addContact(strXMLFilePath, strFileName)
Dim objDom
Dim objRoot
Dim objRecord
Dim objField
Dim objFieldValue
Dim objattID
Dim objattTabOrder
Dim objPI
Dim blnFileExists
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
blnFileExists = objDom.Load(strXMLFilePath & "\" & strFileName)
If blnFileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("users")
objDom.appendChild objRoot
End If
'Create the new container element for the new record.
Set objRecord = objDom.createElement("profile")
objRoot.appendChild objRecord 'I think that over here I should write objRoot.prependChild obijRecord. But I am getting an error
For x = 1 To Request.Form.Count
If instr(1,Request.Form.Key(x),"btn") = 0 Then
'Create an element, "field".
Set objField = objDom.createElement(Request.Form.Key(x))
'Create a new element, "field_value".
Set objFieldValue = objDom.createElement(Request.Form.Key(x))
'Set the value of the field_value element equal to the value of the current field in the Form Collection.
objFieldValue.Text = Request.Form(x)
'Append the field element as a child of the new record container element, contact.
objRecord.appendChild objField
'Append the field_value element as a child of the field element.
objField.appendChild objFieldValue
End If
Next
If blnFileExists = False then 'Create the xml processing instruction.
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
'Append the processing instruction to the XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
End If
'Save the XML document.
objDom.save strXMLFilePath & "\" & strFileName
'Release all of your object references.
Set objDom = Nothing
Set objRoot = Nothing
Set objRecord = Nothing
Set objField = Nothing
Set objFieldValue = Nothing
Set objattID = Nothing
Set objattTabOrder = Nothing
Set objPI = Nothing
End Function
%>
Thank-you indvance