Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use XmlReader class?

Tags:

c#

xml

xmlreader

I want to save and load my xml data using XmlReader. But I don't know how to use this class. Can you give me a sample code for start?

like image 791
mohammad reza Avatar asked May 24 '09 16:05

mohammad reza


People also ask

What does XmlReader create FS do?

This method allows you add additional features to an underlying XmlReader object. The underlying XmlReader object can be another XmlReader object created by the Create method, or an XmlReader object created using one of the concrete XmlReader implementations.

What's the difference between XmlDocument and XmlReader?

XmlDocument is very easy to use. Its only real drawback is that it loads the whole XML document into memory to process. Its seductively simple to use. XmlReader is a stream based reader so will keep your process memory utilization generally flatter but is more difficult to use.

How do I read XML files?

View an XML file in a browserIn Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome". When you do, the file will open in a new tab. Note: Instructions for your operating system may differ slightly.

What is XML text reader?

XmlTextReader provides forward-only, read-only access to a stream of XML data. The current node refers to the node on which the reader is positioned. The reader is advanced using any of the read methods and properties reflect the value of the current node.


1 Answers

MSDN has a simple example to get you started here.

If you're interested in reading and writing XML documents, and not just specifically using the XmlReader class, there's a nice article covering a few of your options here.

But if you just want to get started and play around, try this:

 XmlReaderSettings settings = new XmlReaderSettings();
 settings.IgnoreWhitespace = true;
 settings.IgnoreComments = true;
 XmlReader reader = XmlReader.Create("file.xml", settings);
like image 98
Matt Brindley Avatar answered Oct 02 '22 17:10

Matt Brindley