Skip to content

Commit

Permalink
Support .net6, add samples for unity
Browse files Browse the repository at this point in the history
  • Loading branch information
ikorin24 committed Nov 12, 2021
1 parent 8a0a473 commit a0ad1db
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 22 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# U8XmlParser

[![GitHub license](https://img.shields.io/github/license/ikorin24/U8XmlParser?color=FF8821)](https://github.com/ikorin24/U8XmlParser/blob/master/LICENSE)
[![nuget](https://img.shields.io/badge/nuget-v1.1.0-FF8821)](https://www.nuget.org/packages/U8XmlParser)
[![nuget](https://img.shields.io/badge/nuget-v1.1.2-FF8821)](https://www.nuget.org/packages/U8XmlParser)

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

Expand All @@ -11,7 +11,7 @@ U8XmlParser is faster than any other xml libraries. (See the following benchmark

### For .NET

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

Install from [Nuget package](https://www.nuget.org/packages/U8XmlParser/)

Expand All @@ -21,11 +21,22 @@ $ dotnet add package U8XmlParser

### For Unity

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

Install the package from OpenUPM.
See [OpenUPM](https://openupm.com/packages/com.ikorin24.u8xmlparser/) for details.

```sh
$ openupm add com.ikorin24.u8xmlparser
```

Or install the package from UPM by git URL.

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

For Unity 2019 or older, add the following libraries built for .net standard2.0 to your project.
#### **Unity 2019 or older**

Add the following libraries built for .net standard2.0 to your project.
You can get them at the [release page](https://github.com/ikorin24/U8XmlParser/releases).

- U8XmlParser.dll (built for .net standard 2.0)
Expand Down Expand Up @@ -117,7 +128,7 @@ using (XmlObject xml = XmlParser.Parse(stream))

## Benchmark

### Benchmarking Yourself
### Benchmarking by yourself

```cs
$ cd src/Benchmark
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net48</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;net48</TargetFrameworks>
<RootNamespace>U8Xml.Benchmark</RootNamespace>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/U8XmlParser/U8XmlParser.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
<RootNamespace>U8Xml</RootNamespace>
Expand All @@ -14,7 +14,7 @@
<RepositoryUrl>https://github.com/ikorin24/U8XmlParser.git</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryType>git</RepositoryType>
<Version>1.1.0</Version>
<Version>1.1.2</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/U8XmlParserUnity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ crashlytics-build.properties
/[Aa]ssets/[Ss]treamingAssets/aa/*

.vsconfig

!/[Aa]ssets/Plugins/U8XmlParser/*~/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using UnityEngine;

namespace U8Xml.Samples
{
public class U8XmlSample : MonoBehaviour
{
private const string SampleXml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!-- This is a sample xml. -->
<foo>
<bar aaa=""10""/>
<baz>The quick brown fox jumps over the lazy dog</baz>
</foo>
";

private void Start()
{
string rootNodeName;

Debug.Log(SampleXml);
using(var xml = XmlParser.Parse(SampleXml)) {

var root = xml.Root;
rootNodeName = root.Name.ToString();

if(root.TryGetFirstChild(out var node1)) {
var attr = node1.FindAttribute("aaa");
string attrName = attr.Name.ToString();
int attrValue = attr.Value.ToInt32();
Debug.Log($"node1: {node1.Name}, [{attrName} = {attrValue}]");
}

if(root.TryFindChild("baz", out var node2)) {
Debug.Log(node2.InnerText);
}
}

// [NOTE]
// Don't use XmlObject, RawString, or any objects from XmlParser after Dispose().
// All thier memory are already released.
// Evaluate them into int, float, string, etc... if you use after disposed.

Debug.Log($"root node name: {rootNodeName}");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "U8XmlParserSample",
"rootNamespace": "U8Xml.Samples",
"references": [
"GUID:99988bbb805cede47a3a6f22765caf54"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -118,14 +118,17 @@ NavMeshSettings:
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &705507993
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 705507995}
Expand All @@ -141,15 +144,18 @@ GameObject:
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_Enabled: 1
serializedVersion: 8
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
Expand All @@ -159,26 +165,49 @@ Light:
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 1
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &705507995
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
Expand All @@ -191,7 +220,8 @@ Transform:
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 963194228}
Expand All @@ -208,23 +238,26 @@ GameObject:
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_Enabled: 1
--- !u!20 &963194227
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
Expand Down Expand Up @@ -256,7 +289,8 @@ Camera:
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
Expand All @@ -265,3 +299,46 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1980463155
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1980463156}
- component: {fileID: 1980463157}
m_Layer: 0
m_Name: U8XmlSample
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1980463156
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1980463155}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1980463157
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1980463155}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e67af3d64724a38499644e4862e60322, type: 3}
m_Name:
m_EditorClassIdentifier:

0 comments on commit a0ad1db

Please sign in to comment.