ARTX.XPathReader
1.0.1
dotnet add package ARTX.XPathReader --version 1.0.1
NuGet\Install-Package ARTX.XPathReader -Version 1.0.1
<PackageReference Include="ARTX.XPathReader" Version="1.0.1" />
<PackageVersion Include="ARTX.XPathReader" Version="1.0.1" />
<PackageReference Include="ARTX.XPathReader" />
paket add ARTX.XPathReader --version 1.0.1
#r "nuget: ARTX.XPathReader, 1.0.1"
#:package ARTX.XPathReader@1.0.1
#addin nuget:?package=ARTX.XPathReader&version=1.0.1
#tool nuget:?package=ARTX.XPathReader&version=1.0.1
About XPathReader
XPathReader is a .NET/C# library that simplifies the process of reading and extracting data from XML documents using XPath expressions. It uses Source Generators to create a custom reader class based on provided XPath expressions, allowing for memory efficient and fast access to XML data. The name and idea were inspired by Microsoft's XPathReader from early .Net days.
Features
- Source Generators: Automatically generates a reader class based on specified XPath expressions.
- Memory Efficient: Uses
XmlReaderfor low memory consumption when processing large XML files. - Multiple XPath Support: Reads the document once and extracts data for multiple XPath expressions in a single pass.
Usage example
using ARTX.XPath;
public partial class Program
{
[GeneratedXPathReader("/bookstore/books/book/title|/bookstore/journals/journal/publisher")]
public static partial XPathReader BookStoreReader { get; }
static void Main(string[] args)
{
FileStream stream = File.OpenRead("bookstore.xml");
// There is also an async implementation.
// await foreach (ReadResult item in BookStoreReader.ReadAsync(stream, cancellationToken))
foreach (ReadResult item in BookStoreReader.Read(stream))
{
Console.WriteLine(item.NodeReader.ReadOuterXml());
}
// Output:
//<title>GFG</title>
//<title>GFG 2</title >
//<publisher>Publisher 1</publisher>
//<publisher>Publisher 2</publisher>
}
}
Installation
You can install the XPathReader library via NuGet Package Manager:
dotenet add package ARTX.XPathReader
Requirements
- .NET Framework 4.8 or later (requires Language Version 9.0 or later)
- Any .NET version that supports Source Generators
Usage
- Add the
GeneratedXPathReaderattribute to a partial method or property, specifying the XPath expressions.- You can provide multiple XPath expressions separated by
|or new line.
- You can provide multiple XPath expressions separated by
- Call the generated
ReadorReadAsyncmethod, passing in aStreamcontaining the XML data. - These methods return an
IEnumerable<ReadResult>orIAsyncEnumerable<ReadResult>, where eachReadResultcontains anXmlReaderpositioned at the matching node, expected XPath from the attribute that, was encountered, and actual XPath of the returned node.
Limitations
- Only simple XPath expressions are supported (e.g., no predicates, functions, or axes).
- Only absolute paths starting from the root are supported.
- When XPath contains an axis, the error is thrown during compilation.
- When XPath contains predicates, they are ignored, and only the node name is considered.
- Please note that the generator adds a field (static or not) into the declared class. Therefore, interfaces and read-only structs only supported in a static context.
Predicates support is planned for future releases.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 1.0.0)
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 232 | 11/9/2025 |
| 1.0.0 | 201 | 10/27/2025 |
| 0.2.9-beta | 196 | 10/23/2025 |
| 0.2.8-beta | 184 | 10/22/2025 |
| 0.2.7-beta | 185 | 10/19/2025 |
| 0.1.0-beta | 187 | 10/5/2025 |