U8XmlParser 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package U8XmlParser --version 1.0.2                
NuGet\Install-Package U8XmlParser -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="U8XmlParser" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add U8XmlParser --version 1.0.2                
#r "nuget: U8XmlParser, 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 U8XmlParser as a Cake Addin
#addin nuget:?package=U8XmlParser&version=1.0.2

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

U8XmlParser

GitHub license nuget

High performance, thread-safe and IL2CPP-safe C# xml parser.

U8XmlParser is faster than any other xml libraries. (See the following benchmark for more info)

Install

For .NET

.net standard2.0, 2.1, .net framework4.8, .net core3.1, .net5 are supported.

Install from Nuget package

$ dotnet add package U8XmlParser

For Unity

If Unity 2020 or newer, install the package from UPM by git URL.

git URL: (https://github.com/ikorin24/U8XmlParser.git?path=src/U8XmlParserUnity/Assets/Plugins#v1.0.2)

For Unity 2019 or older, add the following libraries built for .net standard2.0 to your project. You can get them at the release page.

  • U8XmlParser.dll (built for .net standard 2.0)
  • System.Buffers.dll
  • System.Memory.dll
  • System.Runtime.CompilerServices.Unsafe.dll

How to Build

It requires dotnet cli tools. (or Visual Studio)

$ git clone https://github.com/ikorin24/U8XmlParser.git
$ cd U8XmlParser
$ dotnet src/U8XmlParser/U8XmlParser.csproj -c Release

How to Use

General usage

/* ------- your_file.xml ----------

<?xml version="1.0" encoding="UTF-8">
<SomeData>
    <Data aa="20">bbb</Data>
    <Data aa="30">ccc</Data>
</SomeData>

----------------------------------- */

// using System.IO;
// using U8Xml;

using (Stream stream = File.OpenRead("your_file.xml"))
using (XmlObject xml = XmlParser.Parse(stream))
{
    XmlNode root = xml.Root;
    string rootName = root.Name.ToString();         // "SomeData"

    // node
    XmlNode child = root.Children.First();
    string childName = child.Name.ToString();       // "Data"
    string innerText = child.InnerText.ToString();  // "bbb"
    
    // attribute
    XmlAttribute attr = child.Attributes.First();
    string attrName = attr.Name.ToString();         // "aa"
    int attrValue = attr.Value.ToInt32();           // 20

    // children nodes enumeration
    foreach(XmlNode node in root.Children)
    {
        // do something
    }
}
// *** DO NOT use any object from the parser. ***
// XmlObject, XmlNode, RawString, etc... are no longer accessible here.
// Their all memories are released when XmlObject.Dispose() called !!
// They must be evaluated and converted to string, int, and so on.

Entity resolving

Some xml has DTD; Document Type Declaration, and it can contain Entity Declaration. Entity defines alias of string in the xml. (For example, 'lt' is defined as alias of '<' by default. We have to resolve it when appears &lt; in xml.)

/* ------- your_file.xml ----------

<?xml version="1.0" encoding="UTF-8">
<SomeData>
    &lt;foo&gt;
</SomeData>

----------------------------------- */

// using System.IO;
// using U8Xml;

using (Stream stream = File.OpenRead("your_file.xml"))
using (XmlObject xml = XmlParser.Parse(stream))
{
    RawString innerText = xml.Root.InnerText;   // "&lt;foo&gt;"
    XmlEntityTable entities = xml.EntityTable;
    string resolvedText = entities.ResolveToString(innerText);  // "<foo>"
}

Benchmark

Benchmarking Yourself

$ cd src/Benchmark
$ dotnet run -c Release -f net5.0

Results (on .net5)

Benchmarked by BenchmarkDotNet.

Large XML File (about 1MB)

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-10700 CPU 2.90GHz, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=6.0.100-preview.4.21255.9
  [Host]     : .NET Core 5.0.6 (CoreCLR 5.0.621.22011, CoreFX 5.0.621.22011), X64 RyuJIT
  Job-FFRSPZ : .NET Core 5.0.6 (CoreCLR 5.0.621.22011, CoreFX 5.0.621.22011), X64 RyuJIT

Jit=RyuJit  Platform=X64  InvocationCount=1  
IterationCount=100  UnrollFactor=1  

Method Mean Error StdDev Ratio RatioSD Rank Gen 0 Gen 1 Gen 2 Allocated
'U8Xml.XmlParser (my lib)' 22.51 ms 0.035 ms 0.099 ms 1.00 0.00 1 - - - 64 B
System.Xml.Linq.XDocument 119.76 ms 0.556 ms 1.639 ms 5.32 0.08 3 7000.0000 4000.0000 1000.0000 51898640 B
System.Xml.XmlDocument 172.68 ms 2.337 ms 6.892 ms 7.68 0.30 4 10000.0000 5000.0000 1000.0000 76709520 B
System.Xml.XmlReader 34.37 ms 0.014 ms 0.038 ms 1.53 0.01 2 - - - 132712 B

Samll XML File (about 100KB)

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-10700 CPU 2.90GHz, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=6.0.100-preview.4.21255.9
  [Host]     : .NET Core 5.0.6 (CoreCLR 5.0.621.22011, CoreFX 5.0.621.22011), X64 RyuJIT
  Job-YGCDZN : .NET Core 5.0.6 (CoreCLR 5.0.621.22011, CoreFX 5.0.621.22011), X64 RyuJIT

Jit=RyuJit  Platform=X64  InvocationCount=1  
IterationCount=100  UnrollFactor=1  

Method Mean Error StdDev Median Ratio RatioSD Rank Gen 0 Gen 1 Gen 2 Allocated
'U8Xml.XmlParser (my lib)' 278.3 μs 0.59 μs 1.65 μs 278.4 μs 1.00 0.00 1 - - - 64 B
System.Xml.Linq.XDocument 1,170.7 μs 34.49 μs 94.98 μs 1,161.3 μs 4.21 0.34 3 - - - 547336 B
System.Xml.XmlDocument 1,442.4 μs 4.29 μs 12.18 μs 1,442.2 μs 5.18 0.05 4 - - - 796912 B
System.Xml.XmlReader 599.7 μs 3.13 μs 9.09 μs 594.8 μs 2.15 0.03 2 - - - 29360 B

License

Author: ikorin24, and all contributors.

This repository is licensed under MIT.

See Licenses of other libraries this repository contains from here.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.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 is compatible.  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 (4)

Showing the top 4 NuGet packages that depend on U8XmlParser:

Package Downloads
OEmbed

A simple oEmbed consumer library for .NET

NiconicoToolkit

ニコニコ動画/生放送の.Net向けサードパーティライブラリです。 - Account (Login with mail/password) - Video (Play, Comment) - Activity (Video History) - Channels (Videos) - Follow (Tag, User, Mylist, Channel, Community) - Likes (Video) - Live (Play, Comment, TimeShift) - Mylist (List videos, Edit MylistGroup) - NicoRepo - Ranking (Video) - Series (List videos) - User - SnapshotSearchV2 (Video) - Search (Video/Mylist/Live)

UnsafeGbxConnector

Package Description

Heroes.XmlData

Library to directly parse the Heroes of the Storm game data.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on U8XmlParser:

Repository Stars
ingen084/KyoshinEewViewerIngen
Custom client for Kyoshin Monitor
Version Downloads Last updated
1.6.1 55,331 5/19/2022
1.6.0 14,956 5/12/2022
1.5.0 3,735 3/15/2022
1.4.0 2,717 1/28/2022
1.3.0 344 12/18/2021
1.2.0 312 12/7/2021
1.1.2 2,604 11/12/2021
1.1.0 403 10/8/2021
1.1.0-pre1 276 9/5/2021
1.0.2 396 8/8/2021
1.0.1 371 5/29/2021
1.0.0 437 5/15/2021