Skip to content

Commit ecde42f

Browse files
ghostghost
authored andcommitted
Add project files.
1 parent 4f50c91 commit ecde42f

File tree

11 files changed

+588
-0
lines changed

11 files changed

+588
-0
lines changed

AngleSharp.XPath.sln

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8B85F292-66CA-44A2-950E-1F81A3E7ECD5}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C6856E2-614E-4528-B356-F22F6E2E37EB}"
9+
ProjectSection(SolutionItems) = preProject
10+
global.json = global.json
11+
EndProjectSection
12+
EndProject
13+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AngleSharp.XPath", "src\AngleSharp.XPath\AngleSharp.XPath.xproj", "{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD}"
14+
EndProject
15+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AngleSharp.XPath.Tests", "src\AngleSharp.XPath.Tests\AngleSharp.XPath.Tests.xproj", "{5BA4134A-2E43-4219-893D-85F1481A0FCC}"
16+
EndProject
17+
Global
18+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
19+
Debug|Any CPU = Debug|Any CPU
20+
Release|Any CPU = Release|Any CPU
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{5BA4134A-2E43-4219-893D-85F1481A0FCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{5BA4134A-2E43-4219-893D-85F1481A0FCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{5BA4134A-2E43-4219-893D-85F1481A0FCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{5BA4134A-2E43-4219-893D-85F1481A0FCC}.Release|Any CPU.Build.0 = Release|Any CPU
31+
EndGlobalSection
32+
GlobalSection(SolutionProperties) = preSolution
33+
HideSolutionNode = FALSE
34+
EndGlobalSection
35+
GlobalSection(NestedProjects) = preSolution
36+
{247B6597-EFDC-4A4D-BBB2-B26CFD15FBBD} = {8B85F292-66CA-44A2-950E-1F81A3E7ECD5}
37+
{5BA4134A-2E43-4219-893D-85F1481A0FCC} = {8B85F292-66CA-44A2-950E-1F81A3E7ECD5}
38+
EndGlobalSection
39+
EndGlobal

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "test" ],
3+
"sdk": {
4+
"version": "1.0.0-preview2-003131"
5+
}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>5ba4134a-2e43-4219-893d-85f1481a0fcc</ProjectGuid>
10+
<RootNamespace>AngleSharp.XPath.Tests</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
20+
</ItemGroup>
21+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
22+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using AngleSharp.XPath;
7+
8+
namespace AngleSharp.XPath.Tests
9+
{
10+
[TestFixture]
11+
public class HtmlDocumentNavigatorTests
12+
{
13+
[Test]
14+
public async Task SelectSinleNodeTest()
15+
{
16+
var config = Configuration.Default.WithDefaultLoader();
17+
var address = "https://stackoverflow.com/questions/39471800/is-anglesharps-htmlparser-threadsafe";
18+
var document = await BrowsingContext.New(config).OpenAsync(address);
19+
20+
var content = document.DocumentElement.SelectSingleNode("//div[@id='content']");
21+
Assert.That(content, Is.Not.Null);
22+
}
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("AngleSharp.XPath.Tests")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("5ba4134a-2e43-4219-893d-85f1481a0fcc")]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "1.0.0-*",
3+
4+
"dependencies": {
5+
"AngleSharp": "0.9.8.1",
6+
"AngleSharp.XPath": "1.0.0-*",
7+
"NETStandard.Library": "1.6.0",
8+
"NUnit": "3.4.1",
9+
"dotnet-test-nunit": "3.4.0-beta-2"
10+
},
11+
12+
"testRunner": "nunit",
13+
14+
"tools": {},
15+
"frameworks": {
16+
"netcoreapp1.0": {
17+
"imports": "portable-net45+win8",
18+
"dependencies": {
19+
"Microsoft.NETCore.App": {
20+
"version": "1.0.0-*",
21+
"type": "platform"
22+
}
23+
}
24+
}
25+
},
26+
"runtimes": {
27+
"win10-x64": {},
28+
"osx.10.10-x64": {}
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>247b6597-efdc-4a4d-bbb2-b26cfd15fbbd</ProjectGuid>
11+
<RootNamespace>AngleSharp.XPath</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>

src/AngleSharp.XPath/Extensions.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using AngleSharp.Dom;
2+
using AngleSharp.Dom.Html;
3+
using System;
4+
using System.Diagnostics;
5+
using System.Xml;
6+
using System.Xml.XPath;
7+
8+
namespace AngleSharp.XPath
9+
{
10+
public static class Extensions
11+
{
12+
public static XPathNavigator CreateNavigator(this IHtmlDocument document)
13+
{
14+
if (document == null)
15+
{
16+
throw new ArgumentNullException(nameof(document));
17+
}
18+
19+
return new HtmlDocumentNavigator(document, document.DocumentElement);
20+
}
21+
22+
[DebuggerStepThrough]
23+
public static string GetOrAdd(this XmlNameTable table, string array)
24+
{
25+
string s = table.Get(array);
26+
27+
if (s == null)
28+
{
29+
return table.Add(array);
30+
}
31+
32+
return s;
33+
}
34+
35+
public static INode SelectSingleNode(this IElement element, string xpath)
36+
{
37+
if (element == null)
38+
{
39+
throw new ArgumentNullException(nameof(element));
40+
}
41+
42+
if (xpath == null)
43+
{
44+
throw new ArgumentNullException(nameof(xpath));
45+
}
46+
47+
HtmlDocumentNavigator nav = new HtmlDocumentNavigator(element.Owner, element);
48+
XPathNodeIterator it = nav.Select(xpath);
49+
50+
if (!it.MoveNext())
51+
{
52+
return null;
53+
}
54+
55+
HtmlDocumentNavigator node = (HtmlDocumentNavigator)it.Current;
56+
return node.CurrentNode;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)