Solved

XmlElement to XmlReader?

Posted on 2011-09-28
3
3,709 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL - substring between 2 commas 12 20
DTD and JAVA versions 1 27
ASP AND XML 3 30
ASP.net Will we ever be able to build mobile apps in it 6 27
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 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