ARTX.XPathReader 1.0.1

dotnet add package ARTX.XPathReader --version 1.0.1
                    
NuGet\Install-Package ARTX.XPathReader -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ARTX.XPathReader" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ARTX.XPathReader" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ARTX.XPathReader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ARTX.XPathReader --version 1.0.1
                    
#r "nuget: ARTX.XPathReader, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ARTX.XPathReader@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ARTX.XPathReader&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ARTX.XPathReader&version=1.0.1
                    
Install as a Cake Tool

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 XmlReader for 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

  1. Add the GeneratedXPathReader attribute to a partial method or property, specifying the XPath expressions.
    • You can provide multiple XPath expressions separated by | or new line.
  2. Call the generated Read or ReadAsync method, passing in a Stream containing the XML data.
  3. These methods return an IEnumerable<ReadResult> or IAsyncEnumerable<ReadResult>, where each ReadResult contains an XmlReader positioned 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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