Skip to content

Commit 09e81fe

Browse files
committed
Changed source to be v0.10 compatible + align with core style
1 parent 2c8f90b commit 09e81fe

File tree

9 files changed

+164
-249
lines changed

9 files changed

+164
-249
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: csharp
2-
solution: AngleSharp.XPath.sln
2+
solution: src/AngleSharp.XPath.sln
33
dotnet : 2.0.3
44
script :
55
- dotnet restore

src/AngleSharp.XPath.Tests/HtmlDocumentNavigableTests.cs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
#region License
2-
// MIT License
3-
//
4-
// Copyright (c) 2018 Denis Ivanov
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
#endregion
24-
25-
using System;
26-
using AngleSharp.Parser.Html;
27-
using NUnit.Framework;
28-
291
namespace AngleSharp.XPath.Tests
302
{
3+
using AngleSharp.Html.Parser;
4+
using NUnit.Framework;
5+
using System;
6+
317
[TestFixture]
328
public class HtmlDocumentNavigableTests
339
{
@@ -47,7 +23,7 @@ public void CreateNavigator_Call_ShouldReturnHtmlDocumentNavigator()
4723
{
4824
// Arrange
4925
var parser = new HtmlParser();
50-
var document = parser.Parse("<html></html>");
26+
var document = parser.ParseDocument("<html></html>");
5127
var navigable = new HtmlDocumentNavigable(document);
5228

5329
// Act

src/AngleSharp.XPath.Tests/HtmlDocumentNavigatorTests.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
1-
#region License
2-
// MIT License
3-
//
4-
// Copyright (c) 2018 Denis Ivanov
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
#endregion
24-
25-
using NUnit.Framework;
26-
using System.Threading.Tasks;
27-
using AngleSharp.Parser.Html;
28-
291
namespace AngleSharp.XPath.Tests
302
{
31-
[TestFixture]
3+
using AngleSharp.Html.Parser;
4+
using NUnit.Framework;
5+
using System.Threading.Tasks;
6+
7+
[TestFixture]
328
public class HtmlDocumentNavigatorTests
339
{
3410
[Test, Retry(5)]
@@ -57,7 +33,7 @@ public void SelectNodes_SelectList_ShouldReturnList()
5733
<li>Third</li>
5834
</ol>";
5935
var parser = new HtmlParser();
60-
var document = parser.Parse(html);
36+
var document = parser.ParseDocument(html);
6137

6238
// Act
6339
var nodes = document.DocumentElement.SelectNodes("//li");

AngleSharp.XPath.sln renamed to src/AngleSharp.XPath.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngleSharp.XPath", "src\AngleSharp.XPath\AngleSharp.XPath.csproj", "{9ACD9018-0E38-4617-A61E-2F49D8A14E3A}"
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngleSharp.XPath", "AngleSharp.XPath\AngleSharp.XPath.csproj", "{9ACD9018-0E38-4617-A61E-2F49D8A14E3A}"
44
EndProject
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngleSharp.XPath.Tests", "src\AngleSharp.XPath.Tests\AngleSharp.XPath.Tests.csproj", "{9B099D34-CD68-47F5-92F2-DA34567A0223}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngleSharp.XPath.Tests", "AngleSharp.XPath.Tests\AngleSharp.XPath.Tests.csproj", "{9B099D34-CD68-47F5-92F2-DA34567A0223}"
66
EndProject
77
Global
88
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>1.0.2</Version>
3+
<Version>1.1.0</Version>
44
<Authors>Denis Ivanov</Authors>
55
<PackageId>AngleSharp.XPath</PackageId>
6-
<AssemblyVersion>1.0.2</AssemblyVersion>
7-
<FileVersion>1.0.2</FileVersion>
6+
<AssemblyVersion>1.1.0</AssemblyVersion>
7+
<AssemblyName>AngleSharp.XPath</AssemblyName>
8+
<RootNamespace>AngleSharp.XPath</RootNamespace>
9+
<TargetFramework>netstandard2.0</TargetFramework>
10+
<FileVersion>1.1.0</FileVersion>
811
<Description>XPath support for AngleSharp</Description>
9-
<PackageProjectUrl>https://github.com/denis-ivanov/AngleSharp.XPath/</PackageProjectUrl>
10-
<PackageLicenseUrl>https://github.com/denis-ivanov/AngleSharp.XPath/blob/master/LICENSE</PackageLicenseUrl>
12+
<PackageProjectUrl>https://github.com/AngleSharp/AngleSharp.XPath/</PackageProjectUrl>
13+
<PackageLicenseUrl>https://github.com/AngleSharp/AngleSharp.XPath/blob/master/LICENSE</PackageLicenseUrl>
1114
<PackageTags>HTML XPath AngleSharp</PackageTags>
15+
<SignAssembly>true</SignAssembly>
16+
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
17+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1218
</PropertyGroup>
13-
<PropertyGroup>
14-
<TargetFramework>netstandard2.0</TargetFramework>
15-
</PropertyGroup>
16-
<PropertyGroup>
17-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
18-
</PropertyGroup>
19+
1920
<ItemGroup>
20-
<PackageReference Include="AngleSharp" Version="0.9.9.1" />
21+
<PackageReference Include="AngleSharp" Version="0.10.0" />
22+
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0" />
2123
</ItemGroup>
24+
25+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
26+
<DelaySign>false</DelaySign>
27+
</PropertyGroup>
2228
</Project>

src/AngleSharp.XPath/Extensions.cs

Lines changed: 51 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
1-
#region License
2-
// MIT License
3-
//
4-
// Copyright (c) 2018 Denis Ivanov
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
#endregion
24-
25-
using AngleSharp.Dom;
26-
using AngleSharp.Dom.Html;
27-
using System;
28-
using System.Collections.Generic;
29-
using System.Diagnostics;
30-
using System.Xml;
31-
using System.Xml.XPath;
32-
331
namespace AngleSharp.XPath
342
{
35-
public static class Extensions
3+
using AngleSharp.Dom;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Xml;
8+
using System.Xml.XPath;
9+
10+
/// <summary>
11+
/// Hosts the extension methods for XPath parsing.
12+
/// </summary>
13+
public static class Extensions
3614
{
37-
public static XPathNavigator CreateNavigator(this IHtmlDocument document)
15+
/// <summary>
16+
/// Creates a new navigator for the given document.
17+
/// </summary>
18+
/// <param name="document">The document to extend.</param>
19+
/// <returns>The navigator for XPath expressions.</returns>
20+
public static XPathNavigator CreateNavigator(this IDocument document)
3821
{
39-
if (document == null)
40-
{
41-
throw new ArgumentNullException(nameof(document));
42-
}
43-
44-
return new HtmlDocumentNavigator(document, document.DocumentElement);
22+
var doc = document ?? throw new ArgumentNullException(nameof(document));
23+
return new HtmlDocumentNavigator(doc, doc.DocumentElement);
4524
}
4625

4726
[DebuggerStepThrough]
48-
public static string GetOrAdd(this XmlNameTable table, string array)
27+
internal static String GetOrAdd(this XmlNameTable table, String array)
4928
{
5029
var s = table.Get(array);
5130

@@ -57,51 +36,42 @@ public static string GetOrAdd(this XmlNameTable table, string array)
5736
return s;
5837
}
5938

60-
public static INode SelectSingleNode(this IElement element, string xpath)
39+
/// <summary>
40+
/// Selects a single node (or returns null) matching the <see cref="XPath"/> expression.
41+
/// </summary>
42+
/// <param name="element">The element to start looking from.</param>
43+
/// <param name="xpath">The XPath expression.</param>
44+
/// <returns>The node matching <paramref name="xpath"/> query, if any.</returns>
45+
/// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
46+
public static INode SelectSingleNode(this IElement element, String xpath)
6147
{
62-
if (element == null)
63-
{
64-
throw new ArgumentNullException(nameof(element));
65-
}
66-
67-
if (xpath == null)
68-
{
69-
throw new ArgumentNullException(nameof(xpath));
70-
}
48+
var el = element ?? throw new ArgumentNullException(nameof(element));
49+
var xp = xpath ?? throw new ArgumentNullException(nameof(xpath));
50+
var nav = new HtmlDocumentNavigator(el.Owner, el);
51+
var it = nav.Select(xp);
7152

72-
var nav = new HtmlDocumentNavigator(element.Owner, element);
73-
var it = nav.Select(xpath);
53+
if (it.MoveNext())
54+
{
55+
var node = (HtmlDocumentNavigator)it.Current;
56+
return node.CurrentNode;
57+
}
7458

75-
if (!it.MoveNext())
76-
{
77-
return null;
78-
}
79-
80-
var node = (HtmlDocumentNavigator)it.Current;
81-
return node.CurrentNode;
59+
return null;
8260
}
8361

84-
/// <summary>
85-
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
86-
/// </summary>
87-
/// <param name="element"></param>
88-
/// <param name="xpath">The XPath expression.</param>
89-
/// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
90-
/// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
91-
public static List<INode> SelectNodes(this IElement element, string xpath)
92-
{
93-
if (element == null)
94-
{
95-
throw new ArgumentNullException(nameof(element));
96-
}
97-
98-
if (xpath == null)
99-
{
100-
throw new ArgumentNullException(nameof(xpath));
101-
}
102-
103-
var nav = new HtmlDocumentNavigator(element.Owner, element);
104-
var it = nav.Select(xpath);
62+
/// <summary>
63+
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
64+
/// </summary>
65+
/// <param name="element">The element to start looking from.</param>
66+
/// <param name="xpath">The XPath expression.</param>
67+
/// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
68+
/// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
69+
public static List<INode> SelectNodes(this IElement element, String xpath)
70+
{
71+
var el = element ?? throw new ArgumentNullException(nameof(element));
72+
var xp = xpath ?? throw new ArgumentNullException(nameof(xpath));
73+
var nav = new HtmlDocumentNavigator(el.Owner, el);
74+
var it = nav.Select(xp);
10575
var result = new List<INode>();
10676

10777
while (it.MoveNext())

src/AngleSharp.XPath/HtmlDocumentNavigable.cs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
1-
#region License
2-
// MIT License
3-
//
4-
// Copyright (c) 2018 Denis Ivanov
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
#endregion
24-
25-
using System;
26-
using System.Xml.XPath;
27-
using AngleSharp.Dom.Html;
28-
291
namespace AngleSharp.XPath
302
{
3+
using AngleSharp.Dom;
4+
using System;
5+
using System.Xml.XPath;
6+
317
/// <inheritdoc />
328
public class HtmlDocumentNavigable : IXPathNavigable
339
{
34-
private readonly IHtmlDocument _document;
10+
private readonly IDocument _document;
3511

36-
/// <inheritdoc />
37-
public HtmlDocumentNavigable(IHtmlDocument document)
12+
/// <summary>
13+
/// Creates a new wrapper for navigations regarding the provided document.
14+
/// </summary>
15+
/// <param name="document">The document to create navigators for.</param>
16+
public HtmlDocumentNavigable(IDocument document)
3817
{
3918
_document = document ?? throw new ArgumentNullException(nameof(document));
4019
}

0 commit comments

Comments
 (0)