Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML VB.NET Append
I am using VB code to update an XML file with root.AppendChild. It was working correctly in the beginning but now it is overwriting an existing node instead of adding a new node. Why would this happen?
 
Try
    Dim picStr As String
    picStr = Request.QueryString("picInfo")
    Dim strArray(10) As String
 
    strArray(0) = picStr.Split("/")(0)
    strArray(1) = picStr.Split("/")(1)
    strArray(2) = picStr.Split("/")(2)
    strArray(3) = picStr.Split("/")(3)
    strArray(4) = picStr.Split("/")(4)
    strArray(5) = picStr.Split("/")(5)
    strArray(6) = picStr.Split("/")(6)
    strArray(7) = picStr.Split("/")(7)
    strArray(8) = picStr.Split("/")(8)
    strArray(9) = picStr.Split("/")(9)
 
    msg = strArray(3)
    Dim newPerson As String = _
        "<image ID='" & strArray(0) & "'>" & Environment.NewLine & " " & _
        "   <filename>" & strArray(0) & "</filename>" & Environment.NewLine & " " & _
        "   <caption>" & strArray(1) & "</caption>" & Environment.NewLine & " " & _
        "</image>"
 
    Dim xd As New XmlDocument()
    xd.Load(Server.MapPath("../gallery/All/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/AwardsPatrol/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/FundRaising/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/NPS-History/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/NPS-Today/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/Projects/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/SponsorsAndSupporters/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/StudentLife/gallery.xml"))
    Dim docFrag As XmlDocumentFragment = xd.CreateDocumentFragment()
    docFrag.InnerXml = newPerson
    Dim root As XmlNode = xd.DocumentElement
    root.AppendChild(docFrag)
 
    ' Save the Xml.
    If CInt(strArray(2)) = 1 Then
        xd.Save(Server.MapPath("../gallery/All/gallery.xml"))
    End If
    If CInt(strArray(3)) = 1 Then
        xd.Save(Server.MapPath("../gallery/AwardsPatrol/gallery.xml"))
    End If
    If CInt(strArray(4)) = 1 Then
        xd.Save(Server.MapPath("../gallery/FundRaising/gallery.xml"))
    End If
    If CInt(strArray(5)) = 1 Then
        xd.Save(Server.MapPath("../gallery/NPS-History/gallery.xml"))
    End If
    If CInt(strArray(6)) = 1 Then
        xd.Save(Server.MapPath("../gallery/NPS-Today/gallery.xml"))
    End If
    If CInt(strArray(7)) = 1 Then
        xd.Save(Server.MapPath("../gallery/Projects/gallery.xml"))
    End If
    If CInt(strArray(8)) = 1 Then
        xd.Save(Server.MapPath("../gallery/SponsorsAndSupporters/gallery.xml"))
    End If
    If CInt(strArray(9)) = 1 Then
        xd.Save(Server.MapPath("../gallery/StudentLife/gallery.xml"))
    End If
 
    Response.Redirect("uploadPics.aspx")
Catch
    Dim TextFile As New StreamWriter(myErrorDir & "errorUploadPicsConfirm_Submit.txt")    'C:\EHC\error\
    TextFile.WriteLine(ex)
    TextFile.Close()
    myExcepValue = ex.ToString()
    If myExcepValue = ("cannot be a zero-length string") Then
        myerror = ("<font color=red size=3>Please fill out all required fields. Thank you.</font>")
        Response.Write(myerror)
    ElseIf myExcepValue.Contains("Thread was being aborted") Then
        'Do nothing. This error is generated by response.redirect by design.
    ElseIf myExcepValue.Contains("No data exists for the row/column") Then
        'Do nothing. This is probably for the spam table.
    Else
        'Call exceptionEmail()
    End If
End Try
Posted 26-Oct-12 12:42pm
Edited 26-Oct-12 12:43pm
v2
Comments
Sergey Alexandrovich Kryukov at 26-Oct-12 19:29pm
   
What does it mean: "unload"?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100