Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/.gradle
/.idea
/*/bin
/*/obj
/build
.idea/
bin/
obj/
build/
*.DotSettings.user
.DS_Store
/XmlResolverData/Data
Expand Down
2 changes: 1 addition & 1 deletion DataTests/BaseTestRoot.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using XmlResolver.Utils;

namespace UnitTests;
namespace DataTests;

public class BaseTestRoot
{
Expand Down
2 changes: 1 addition & 1 deletion DataTests/DataTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion DataTests/ResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using XmlResolver.Features;
using XmlResolver.Utils;

namespace UnitTests;
namespace DataTests;

public class ResolverTest : BaseTestRoot
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ files, or from assemblies bundled with your application.
## Version 6.x

Version 6.x is a significant refactoring and is not backwards compatible with version 2.x.
(The underlying functionality is the same, but the API is slightly different.)
(The underlying functionality is the same, but the API is different.)
The version 2.x sources are now in the
[legacy_v2](https://github.com/xmlresolver/xmlresolvercs/tree/legacy_v2) branch. Important
bug fixes will be applied to the 2.x release for some time, but new development is
Expand Down
19 changes: 19 additions & 0 deletions SampleApp/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true">

<variable name="appName" value="SampleApp" />

<targets async="true">
<target xsi:type="Console"
name="default"
layout="${level:uppercase=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
/>

</targets>
<rules>
<logger name="*" writeTo="default" minlevel="Info" />
</rules>
</nlog>
76 changes: 76 additions & 0 deletions SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using NLog;
using XmlResolver;
using XmlResolver.Features;

namespace SampleApp;

class Program {
protected static readonly ResolverLogger logger = new(LogManager.GetCurrentClassLogger());

static void Main(string[] args) {
XmlResolverConfiguration config = new XmlResolverConfiguration();
// The SampleApp refers to the XmlResolverData NuGet, so I can assume all of
// the common resources in that assembly will be available.
//config.SetFeature(ResolverFeature.ASSEMBLY_CATALOGS, "XmlResolverData.dll");
config.SetFeature(ResolverFeature.ASSEMBLY_CATALOGS, "./mydata.dll");

string document = null;

// Crude parse of the command line arguments
int pos = 0;
while (pos < args.Length) {
string arg = args[pos];

if ("-c".Equals(arg)) {
config.AddCatalog(args[pos + 1]);
pos += 1;
} else if (arg.StartsWith("-c")) {
config.AddCatalog(arg.Substring(2));
}
else {
document = arg;
}

pos += 1;
}

if (document != null) {
Console.WriteLine("Parsing " + document);
List<string> catalogs = (List<String>)config.GetFeature(ResolverFeature.CATALOG_FILES);
Console.WriteLine("Using catalogs: " + String.Join(", ", catalogs));

var resolver = new XmlResolver.XmlResolver(config);

XmlReaderSettings settings = new XmlReaderSettings
{
Async = false,
DtdProcessing = DtdProcessing.Parse,
ValidationType = ValidationType.DTD,
XmlResolver = resolver.GetXmlResolver()
};

int count = 0;
try {
using FileStream fs = File.OpenRead(document);
using (XmlReader reader = XmlReader.Create(fs, settings)) {
while (reader.Read()) {
count += 1;
}
}
Console.WriteLine("Counted " + count + " items in the document.");
}
catch (Exception ex) {
Console.WriteLine("Well, that didn't work like we expected, did it?");
Console.WriteLine(ex.Message);
}
}
else {
Console.WriteLine("Usage: SampleApp [-c catalog]* document.xml");
}
}
}

24 changes: 24 additions & 0 deletions SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\XmlResolver\XmlResolver.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="NuGet.Frameworks" Version="7.0.1" />
<PackageReference Include="System.IO.Packaging" Version="10.0.1" />
<PackageReference Include="XmlResolverData" Version="6.0.3" />
</ItemGroup>

</Project>
Loading