LINQ To XML

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
How can I create a Parent around the current element I am in? Say I am at the second job xElement in the following xml (with jobID = 2) and I want to nest it in a new parent <Order> element using Linq to XML. I am using VB, but a C# example
is fine too. Im looking for something like currentElement.AddParent("Name") or something.
<Document><br/>
<Job><br/>
<JobID>1</JobID><br/>
</Job><br/>
<Job><br/>
<JobID>2</JobID><br/>
</Job><br/>
<Job><br/>
<JobID>3</JobID><br/>
</Job><br/>
</Document>
This is the result I am looking for:
<Document><br/>
<Job><br/>
<JobID>1</JobID><br/>
</Job><br/>
<Order> <br/>
<Job><br/>
<JobID>2</JobID><br/>
</Job><br/>
</Order> <br/>
<Job><br/>
<JobID>3</JobID><br/>
</Job><br/>
</Document>
<hr class="sig Scott Witherell Application Developer, Lewisville, TX

View the full article
 

Similar threads

Back
Top