XmlElement to XmlReader?

I need to figure out how to convert an XmlNode or XmlElement object into a stream so XmlReader can read it and validate against a schema. I can easily get the XmlReader to read from a file but I need it to read from an XmlElement in memory. Please help!
LVL 20
Russ SuterAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
käµfm³d 👽Connect With a Mentor Commented:
How about something like this?
XmlDocument x = new XmlDocument();
XmlNode xel;

x.Load("input.xml");
xel = x.SelectSingleNode("//StudentName");

System.IO.StringReader reader = new System.IO.StringReader(xel.OuterXml);

XmlReader xReader = XmlReader.Create(reader);

Open in new window

0
 
Russ SuterAuthor Commented:
I never thought to use StringReader instead of StreamReader. Sometimes you can't see the forest for the trees eh? That worked a treat. Thanks!
0
 
käµfm³d 👽Commented:
NP. Glad to help  = )
0
All Courses

From novice to tech pro — start learning today.