expat-bindings 1.0.2

dotnet add package expat-bindings --version 1.0.2
NuGet\Install-Package expat-bindings -Version 1.0.2
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="expat-bindings" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add expat-bindings --version 1.0.2
#r "nuget: expat-bindings, 1.0.2"
#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.
// Install expat-bindings as a Cake Addin
#addin nuget:?package=expat-bindings&version=1.0.2

// Install expat-bindings as a Cake Tool
#tool nuget:?package=expat-bindings&version=1.0.2

Expat

Nuget<br> Expat bindings for .NET/C#.

About

Expat, a C99 library for parsing XML 1.0 Fourth Edition, started by James Clark in 1997. Expat is a stream-oriented XML parser. This means that you register handlers with the parser before starting the parse. These handlers are called when the parser discovers the associated structures in the document being parsed from.

Bindings

These bindings are intended to provide most of the features available between libexpat and .NET

All P/Invoking functions added can be found in PInvoke class that is publicy visible.

Basic Parser

This bindings already has a simple parser implemented by default, which basically will redirect all of the P/Invoking callbacks and convert in a simple and practical way and will fire the events as needed.


// using vcpkg helper to resolve libexpat location.

LibraryResolver.UseVcpkg(@"C:\VCPKG", "x64-windows");

using (var parser = new Parser())
{
    int depth = 0;

    parser.OnElementStart += (e) =>
    {
        Console.WriteLine(new string(' ', depth++)
            + "Element: " + e.Name);

        if (e.Attributes.Any())
        {
            var maxPad = e.Attributes.Select(x => x.Key).Max(x => x.Length);

            depth += 2;

            foreach (var (name, value) in e.Attributes)
                Console.WriteLine(new string(' ', depth) + "Attribute: name={0}, value={1}", name.PadLeft(maxPad), value);

            depth -= 2;
        }
    };

    parser.OnText += (e) =>
    {
        if (string.IsNullOrWhiteSpace(e.Value))
            return;

        Console.WriteLine(new string(' ', depth) + "Text: " + HttpUtility.UrlEncode(e.Value));
    };

    parser.OnComment += (e) =>
    {
        Console.WriteLine(new string(' ', depth) + "Comment: " + e.Value);
    };

    parser.OnCdata += (e) =>
    {
        Console.WriteLine(new string(' ', depth) + "Cdata: " +
            e.Value
            .Replace("\n", "\\n")
            .Replace("\r", "\\r")
            .Replace("\f", "\\f")
            .Replace("\t", "\\t"));
    };

    parser.OnProcessingInstruction += (e) =>
    {
        Console.WriteLine("ProcessingInstruction: target={0}, data={1}", e.Target, e.Data);
    };

    parser.OnElementEnd += (e) =>
    {
        Console.WriteLine(new string(' ', --depth) + "EndElement: {0}", e.Value);
    };

    parser.OnProlog += (e) =>
    {
        Console.WriteLine("Prolog: version={0}, encoding={1}, standalone={2}", e.Version,
            e.Encoding.WebName, e.Standalone);
    };

    try
    {
        var fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample.xml");
        using var fs = File.OpenRead(fileName);

        var buf = new byte[8];
        int count;

        // simulate long I/O operation (eg.: network socket)

        while ((count = fs.Read(buf)) > 0)
            parser.Feed(buf, count, fs.Position != fs.Length - 1);

        parser.Feed(buf, 0);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }
}

// parser automatically disposed here.


Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • 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.2 203 11/21/2023
1.0.1 157 6/23/2023
1.0.0 123 6/23/2023