On Apr 17, 8:52*am, Martin Honnen <mahotr...@yahoo.de> wrote:
> CSharper wrote:
> > I have an xml file with bunch of nodes of "Personal" information. I
> > have a XElement which I need to add it to the end of the file of
> > existing Personal XDocument. What is the best way of doing this in
> > Linq or any other way?
>
> Use the LINQ to XML classes like XDocument/XElement e.g.
>
> * *XElement root = XElement.Load("file.xml");
> * *root.Add(yourXElement);
>
> That would add yourXElement as a child of the root element of file.xml.
> You can of course add it elsewhere but then you need to share how your
> XML looks and tell us where you want to insert.
>
> --
>
> * * * * Martin Honnen --- MVP XML
> * * * *http://msmvps.com/blogs/martin_honnen/
Thank you. This is what I have now but code fails with 'This operation
would create an incorrrectly structured document'.
I am using following code
doc.Add(CreateNewNode());
where the CreateNewNode() method returns XElement.
Am i supposed to return something other than XElement? When I create
new document I don't have a problem. it is only when I append.
Thanks,