using (XmlReader reader = XmlReader.Create("file.xml")) { // do something with the reader reader.Close(); }
XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; XmlReader reader = XmlReader.Create("file.xml", settings); try { // do something with the reader } finally { reader.Close(); }In this example, we create an `XmlReader` object with some settings to ignore whitespace. We surround the code that uses the reader with a `try` block, and in the `finally` block, we call the `Close()` method to ensure that the reader is closed even if an exception is thrown. Package/library: System.Xml.