Solved

XmlElement to XmlReader?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 31
Json and asp.net mvc 2 43
Counting connections to SQL Server through C# 3 23
Where can I ask about my ASP.NET MVC project? 6 12
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now