XML prepend Child

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kingpin
    New Member
    • Nov 2006
    • 1

    XML prepend Child

    The reason why I am writing is because I am having trouble with appending information into my XML file and I thought that maybe you 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 anyone help me out?

    This a function that I call in my asp code that appends information into an XML file.

    <%
    addContact "c:\projects\xm l\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(strX MLFilePath, strFileName)
    Dim objDom
    Dim objRoot
    Dim objRecord
    Dim objField
    Dim objFieldValue
    Dim objattID
    Dim objattTabOrder
    Dim objPI
    Dim blnFileExists

    Set objDom = server.CreateOb ject("Microsoft .XMLDOM")
    objDom.preserve WhiteSpace = True
    blnFileExists = objDom.Load(str XMLFilePath & "\" & strFileName)
    If blnFileExists = True Then
    Set objRoot = objDom.document Element
    Else
    Set objRoot = objDom.createEl ement("users")
    objDom.appendCh ild objRoot
    End If

    'Create the new container element for the new record.
    Set objRecord = objDom.createEl ement("profile" )
    objRoot.appendC hild objRecord 'I think that over here I should write objRoot.prepend Child obijRecord. But I am getting an error

    For x = 1 To Request.Form.Co unt
    If instr(1,Request .Form.Key(x),"b tn") = 0 Then
    'Create an element, "field".
    Set objField = objDom.createEl ement(Request.F orm.Key(x))

    'Create a new element, "field_valu e".
    Set objFieldValue = objDom.createEl ement(Request.F orm.Key(x))

    'Set the value of the field_value element equal to the value of the current field in the Form Collection.
    objFieldValue.T ext = Request.Form(x)

    'Append the field element as a child of the new record container element, contact.
    objRecord.appen dChild objField

    'Append the field_value element as a child of the field element.
    objField.append Child objFieldValue
    End If
    Next

    If blnFileExists = False then 'Create the xml processing instruction.
    Set objPI = objDom.createPr ocessingInstruc tion("xml", "version='1.0'" )
    'Append the processing instruction to the XML document.
    objDom.insertBe fore objPI, objDom.childNod es(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
Working...