How can I do this by LINQ?
-
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
andchild2
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.
-
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
andchild2
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.
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
-
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
Nice response. Thank you my friend.