NanoXLSX.Core 3.2.1
Loading...
Searching...
No Matches
XmlStreamUtils.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using System;
9using System.Xml;
10
11namespace NanoXLSX.Utils.Xml
12{
13 // TODO Set to internal in next major release
18 public static class XmlStreamUtils
19 {
24 public static XmlReaderSettings CreateSettings()
25 {
26 return new XmlReaderSettings
27 {
28 XmlResolver = null,
29 IgnoreWhitespace = true,
30 IgnoreComments = true,
31 IgnoreProcessingInstructions = true,
32 };
33 }
34
39 public static bool IsElement(XmlReader reader, string localName)
40 {
41 return reader.NodeType == XmlNodeType.Element
42 && reader.LocalName.Equals(localName, StringComparison.OrdinalIgnoreCase);
43 }
44
50 public static string ReadElementText(XmlReader reader)
51 {
52 if (reader.IsEmptyElement)
53 {
54 return string.Empty;
55 }
56 return reader.ReadElementContentAsString();
57 }
58 }
59}
Static utility class providing helpers for forward-only XmlReader-based (SAX-style) parsing,...
static string ReadElementText(XmlReader reader)
Reads the string content of a simple leaf element (one that contains only text, no child elements)....
static bool IsElement(XmlReader reader, string localName)
Returns true when the reader is positioned on a start element whose LocalName matches localName (Ord...
static XmlReaderSettings CreateSettings()
Creates standardized XmlReaderSettings for all reader plug-ins: XmlResolver=null (security),...