Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. How can I do this by LINQ?

How can I do this by LINQ?

Scheduled Pinned Locked Moved LINQ
questioncsharplinqxml
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi there. I had a XML file like this :

    <Root>
    <Child1>1</Child1>
    <Child2>2</Child2>
    <Child3>3</Child3>
    </Root>

    I want to insert a child node between Child1 and child2 by LINQ. I want to create something like this

    <Root>
    <Child1>1</Chil1d>
    <ChildNew>New</ChildNew>
    <Child2>2</Child2>
    <Child3>3</Child3>
    </Root>

    How can I do it? Thanks in advance.

    H 1 Reply Last reply
    0
    • M Mohammad Dayyan

      Hi there. I had a XML file like this :

      <Root>
      <Child1>1</Child1>
      <Child2>2</Child2>
      <Child3>3</Child3>
      </Root>

      I want to insert a child node between Child1 and child2 by LINQ. I want to create something like this

      <Root>
      <Child1>1</Chil1d>
      <ChildNew>New</ChildNew>
      <Child2>2</Child2>
      <Child3>3</Child3>
      </Root>

      How can I do it? Thanks in advance.

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      VB

         Dim firstElement = xmldoc.Descendants("Child1").First
          firstElement.AddAfterSelf(New XElement("ChildNew") With {.Value = "New"})
      

      Or C#

         var firstElement = xmldoc.Descendants("Child1").First();
         firstElement.AddAfterSelf(new XElement("ChildNew") with {.Value = "New"});
      

      'Howard

      modified on Tuesday, August 12, 2008 10:17 AM

      M 1 Reply Last reply
      0
      • H Howard Richards

        VB

           Dim firstElement = xmldoc.Descendants("Child1").First
            firstElement.AddAfterSelf(New XElement("ChildNew") With {.Value = "New"})
        

        Or C#

           var firstElement = xmldoc.Descendants("Child1").First();
           firstElement.AddAfterSelf(new XElement("ChildNew") with {.Value = "New"});
        

        'Howard

        modified on Tuesday, August 12, 2008 10:17 AM

        M Offline
        M Offline
        Mohammad Dayyan
        wrote on last edited by
        #3

        Nice response. Thank you my friend.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups