I want to create in an app - coded with C# - a copy of the actual element of a XMLReader object by using a XMLDocument instance.
The purpose is to get a copy of the actual reader element, so i can read the inner XML from the actual XML element without moving in the original reader.
When i try to load the reader into the XMLDocument i get the error "The document already has a 'DocumentElement' node.".
Any help would be appreciated.
XmlDocument xmlDocument = new XmlDocument();
MemoryStream streamFromReader = new MemoryStream();
xmlDocument.Load(reader); //Here i get the error
xmlDocument.Save(streamFromReader);
streamFromReader.Position = 0;
XmlReader copyReader = XmlReader.Create(streamFromReader);
sb.Append(copyReader.ReadInnerXml());
copyReader.Close();