I wonder what is the best way to turn a XmlNode
object into an XmlReader
... I could even name a few ways to do this ... But they use a MemoryStream
to make the transformation.
XmlNode content = // My data
using (System.IO.MemoryStream mm = new System.IO.MemoryStream())
{
using (System.Xml.XmlWriter wtr = System.Xml.XmlWriter.Create(mm))
{
content.WriteTo(wtr);
wtr.Flush();
mm.Position = 0;
using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(mm))
{
// Here I have the object
}
}
}
Just use the XmlNodeReader
constructor:
using (XmlReader reader = new XmlNodeReader(content))
{
// ...
}
(The documentation says you should use XmlReader.Create
- but there are no overloads taking an XmlNode
, so that doesn't seem terribly useful to me...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With