Solved

XmlElement to XmlReader?

Posted on 2011-09-28
3
3,606 Views
Last Modified: 2012-05-12
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!
0
Comment
Question by:Russ Suter
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36720333
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
 
LVL 20

Author Closing Comment

by:Russ Suter
ID: 36720385
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36772074
NP. Glad to help  = )
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question