MyHatIsBread
MyHatIsBread

Reputation: 3

How to deep copy XDocument / XElement preserving Line Info

I have an XDocument loaded with LoadOptions.SetLineInfo. I need to take a copy of this object, preserving the line info.

Unfortunately, the copy constructors seem to lose the line info - as does a ToString / Parse.

Any ideas? Thanks.

Upvotes: 0

Views: 241

Answers (1)

vasil oreshenski
vasil oreshenski

Reputation: 2836

You can try creating new XDocument from the old one. Somthing like this.

XDocument original = ....
using(var reader = original.CreateReader())
{
    var copy = XDocument.Load(reader, LoadOptions.SetLineInfo);
}

This should do the trick.

Upvotes: 1

Related Questions