title: XML : Add Nodes in between the specific Node
body: <p>This is my xml doc: </p>
  
  <pre><code>&lt;FolderSettings&gt;
  &lt;quantity&gt;0&lt;/quantity&gt;
  &lt;FolderList&gt;
     &lt;Folder&gt;
      &lt;FolderName&gt;E:\05.09.2016&lt;/FolderName&gt;
      &lt;Checked&gt;true&lt;/Checked&gt;
    &lt;/Folder&gt;
  
    &lt;Folder&gt;
      &lt;FolderName&gt;E:\100CANON&lt;/FolderName&gt;
      &lt;Checked&gt;true&lt;/Checked&gt;
    &lt;/Folder&gt;
  
    &lt;Folder&gt;
      &lt;FolderName&gt;G:\Sony&lt;/FolderName&gt;
      &lt;Checked&gt;true&lt;/Checked&gt;
    &lt;/Folder&gt;
  
  &lt;/FolderList&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want to add Folder node with 2 notes into the FolderList node.</p>
  
  <pre><code>&lt;Folder&gt;
     &lt;FolderName&gt;E:\Nikon&lt;/FolderName&gt;
      &lt;Checked&gt;true&lt;/Checked&gt;
    &lt;/Folder&gt;
  </code></pre>
  
  <p>Every time I select/add a folder, which one is added as a node into FolderList?</p>
  
  <p>How can I do this? I tried something that almost failed.</p>
  
  <p>this is my code for added note into FolderList node</p>
  
  <pre><code>        Dim xmlFile = XDocument.Load(PXmlFileName)
          Dim element = &lt;Folder&gt;
                            &lt;FolderName&gt;&lt;%= _folderPath$ %&gt;&lt;/FolderName&gt;
                            &lt;Checked&gt;&lt;%= "true" %&gt;&lt;/Checked&gt;
                        &lt;/Folder&gt;
          Dim parent = xmlFile...&lt;FolderList&gt;.FirstOrDefault()
          parent.Add(element)
          xmlFile.Save(PXmlFileName)
  </code></pre>
  
  <p>Thanks</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Function UpdateFolderListsIntoXML(_folderPath$) As Boolean
      Dim _xdoc As New XDocument()
      Try
      'Loading: 
          _xdoc = XDocument.Load(PXmlFileName)
          Dim _lamIsElementExists = Function(_elementName$)
                                        Dim _folderlistElement As XElement
                                        Try
                                            _folderlistElement = _xdoc.Root.Element(_elementName$)
                                            If Not IsNothing(_folderlistElement) Then
                                                Return True
                                            Else
                                                Return False
                                            End If
                                        Catch ex As Exception
                                            Return False
                                        Finally
                                            _folderlistElement = Nothing
                                        End Try
                                    End Function
          If _lamIsElementExists("FolderList") = False Then
              'create FolderList element
              _xdoc.Root.Element("FolderSettings").Add(&lt;FolderList&gt;
                                                       &lt;/FolderList&gt;)
              _xdoc.Save(PXmlFileName)
              'After Create "FolderList" Element loading xml file again
              _xdoc = XDocument.Load(PXmlFileName)
          End If
          'Add New Path into FolderList Element
          Dim element = &lt;Folder&gt;
                            &lt;FolderName&gt;&lt;%= _folderPath$ %&gt;&lt;/FolderName&gt;
                            &lt;Checked&gt;&lt;%= "true" %&gt;&lt;/Checked&gt;
                        &lt;/Folder&gt;
          Dim parent = _xdoc...&lt;FolderList&gt;.FirstOrDefault()
          parent.Add(element)
          _xdoc.Save(PXmlFileName)
          Return True
      Catch ex As Exception
          PeX = ex
          Return False
      Finally
          _xdoc = Nothing
      End Try
  End Function
  </code></pre>
  
  <p>this is working fine for me... i appreciate for any suggestion thanks</p>