Results 1 to 3 of 3

Thread: [RESOLVED] XML : Add Nodes in between the specific Node

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    60

    Resolved [RESOLVED] XML : Add Nodes in between the specific Node

    hi this is my xml doc

    HTML Code:
      <Values>
        <quantity>0</quantity>
       <Extenstion>0/Extenstion>
        <FolderList>
           <Folder>
            <FolderName>E:\05.09.2016</FolderName>
            <Checked>true</Checked>
          </Folder>
    
          <Folder>
            <FolderName>E:\100CANON</FolderName>
            <Checked>true</Checked>
          </Folder>
    
          <Folder>
            <FolderName>G:\Sony</FolderName>
            <Checked>true</Checked>
          </Folder>
    
        </FolderList>
      </Values>
    i want to add <Folder> node with 2 notes in between <FolderList>... </FolderList>

    two nodes like
    HTML Code:
     <Folder>
           <FolderName>E:\Nikon</FolderName>
            <Checked>true</Checked>
     </Folder>
    ....
    ...
    ..
    every time i add/select the folder which one want to added into this <FolderList> .... node

    Thanks

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: XML : Add Nodes in between the specific Node

    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    60

    Re: XML : Add Nodes in between the specific Node

    thank KGC ...

    my final code is here

    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(<FolderList>
                                                         </FolderList>)
                _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 = <Folder>
                              <FolderName><%= _folderPath$ %></FolderName>
                              <Checked><%= "true" %></Checked>
                          </Folder>
            Dim parent = _xdoc...<FolderList>.FirstOrDefault()
            parent.Add(element)
            _xdoc.Save(PXmlFileName)
            Return True
        Catch ex As Exception
            PeX = ex
            Return False
        Finally
      _xdoc = Nothing
        End Try
    End Function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width