├── .editorconfig
├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE.md
├── src
├── HtmlAgilityPack.NetStandard1_3
│ └── AssemblyInfo.cs
├── HtmlAgilityPack.NetStandard1_6
│ ├── AssemblyInfo.cs
│ ├── HtmlAgilityPack.snk
│ └── HtmlAgilityPack.NetStandard1_6.csproj
├── HtmlAgilityPack.NetStandard2_0
│ ├── AssemblyInfo.cs
│ └── HtmlAgilityPack.snk
├── HtmlAgilityPack.Net7
│ ├── HtmlAgilityPack.snk
│ └── HtmlAgilityPack.Net7.csproj
├── HtmlAgilityPack.Net20
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Net20.csproj
├── HtmlAgilityPack.Net35
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Net35.csproj
├── HtmlAgilityPack.Net40
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Net40.csproj
├── HtmlAgilityPack.Net45
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Net45.csproj
├── HtmlAgilityPack.UAP10
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.UAP10.csproj
├── HtmlAgilityPack.NetCore45
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.NetCore45.csproj
├── Tests
│ ├── HtmlAgilityPack.Tests.Net45
│ │ ├── mshome.htm
│ │ ├── files
│ │ │ ├── mshome.htm
│ │ │ ├── test.html
│ │ │ ├── overflow.html
│ │ │ ├── attr_quote_expected.html
│ │ │ └── attr_quote.html
│ │ ├── HtmlAgilityPack.snk
│ │ ├── UnitTest1.cs
│ │ ├── packages.config
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── HtmlEntityTest.cs
│ │ ├── HtmlDocument.PreserveOriginalTest.cs
│ │ ├── HtmlAgilityPack.Tests.Net45.csproj
│ │ └── HtmlNode.Tests.cs
│ └── HtmlAgilityPack.Tests.NetStandard2_0
│ │ ├── HtmlAgilityPack.Tests.NetStandard2_0.csproj
│ │ ├── files
│ │ ├── attr_quote_expected.html
│ │ └── attr_quote.html
│ │ ├── EncapsulationTestHtml.cs
│ │ ├── AttributeValueQuoteTests.cs
│ │ ├── HtmlDocument.PreserveOriginalTest.cs
│ │ └── EncapsulatorTests.cs
├── HtmlAgilityPack.NETStandard1_3
│ ├── HtmlAgilityPack.snk
│ └── HtmlAgilityPack.NETStandard1_3.csproj
├── HtmlAgilityPack.Net40-client
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Net40-client.csproj
├── HtmlAgilityPack.Portable-wp8
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Portable-wp8.csproj
├── HtmlAgilityPack.Portable-wp81
│ ├── HtmlAgilityPack.snk
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── HtmlAgilityPack.Portable-wp81.csproj
├── HtmlAgilityPack.Shared
│ ├── HtmlAgilityPack.Shared.shproj.vspscc
│ ├── HtmlAgilityPack.Shared.projitems.vspscc
│ ├── Metro
│ │ ├── InvalidProgramException.cs
│ │ └── HtmlWeb.cs
│ ├── Trace.FullFramework.cs
│ ├── MixedCodeDocumentFragmentType.cs
│ ├── HtmlDocument.Xpath.cs
│ ├── HtmlWebException.cs
│ ├── Trace.cs
│ ├── EncodingFoundException.cs
│ ├── HtmlNodeType.cs
│ ├── NameValuePair.cs
│ ├── HtmlElementFlag.cs
│ ├── MixedCodeDocumentTextFragment.cs
│ ├── HtmlAgilityPack.Shared.shproj
│ ├── HtmlConsoleListener.cs
│ ├── HtmlParseErrorCode.cs
│ ├── IOLibrary.cs
│ ├── HtmlNameTable.cs
│ ├── MixedCodeDocumentCodeFragment.cs
│ ├── HtmlTextNode.cs
│ ├── InvalidProgramException.cs
│ ├── Utilities.cs
│ ├── HtmlCommentNode.cs
│ ├── HtmlParseError.cs
│ ├── MixedCodeDocumentFragment.cs
│ ├── NameValuePairList.cs
│ ├── HtmlAgilityPack.Shared.projitems
│ ├── HtmlCmdLine.cs
│ ├── HtmlNode.Xpath.cs
│ ├── HtmlWeb.Xpath.cs
│ ├── crc32.cs
│ └── MixedCodeDocumentFragmentList.cs
└── HtmlAgilityPack.NETStandard2_0
│ └── HtmlAgilityPack.NETStandard2_0.csproj
├── dapper-plus-sponsor.png
├── entity-framework-extensions-sponsor.png
├── .gitignore
├── .gitattributes
├── LICENSE
└── README.md
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | # C# files
4 | [*.cs]
5 | charset = utf-8-bom
6 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [zzzprojects]
2 | custom: ["https://zzzprojects.com/contribute"]
3 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard1_3/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard1_6/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard2_0/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/dapper-plus-sponsor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/dapper-plus-sponsor.png
--------------------------------------------------------------------------------
/entity-framework-extensions-sponsor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/entity-framework-extensions-sponsor.png
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net7/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net7/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net20/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net20/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net35/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net35/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net40/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net45/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net45/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.UAP10/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.UAP10/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetCore45/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.NetCore45/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/mshome.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/Tests/HtmlAgilityPack.Tests.Net45/mshome.htm
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NETStandard1_3/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.NETStandard1_3/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40-client/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Net40-client/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard1_6/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.NetStandard1_6/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard2_0/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.NetStandard2_0/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp8/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Portable-wp8/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp81/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/HtmlAgilityPack.Portable-wp81/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/files/mshome.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/Tests/HtmlAgilityPack.Tests.Net45/files/mshome.htm
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlAgilityPack.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzzprojects/html-agility-pack/HEAD/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlAgilityPack.snk
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Z.Lab/
2 | [Bb]in/
3 | [Oo]bj/
4 | [Pp]ackages/
5 | Z.Expressions.Eval.NET40/
6 | Z.Lab/
7 | *.suo
8 | *.user
9 | *.userprefs
10 | _ReSharper.*
11 | *.ReSharper.user
12 | *.resharper.user
13 | .vs
14 | *.json
15 | *.sqlite
16 | *.dll
17 | *.pdb
18 | *.xml
19 | *.lock
20 | *.ide
21 | *.ide-shm
22 | *.ide-wal
23 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlAgilityPack.Shared.shproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/UnitTest1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace HtmlAgilityPack.Tests
5 | {
6 | [TestClass]
7 | public class UnitTest1
8 | {
9 | [TestMethod]
10 | public void TestMethod1()
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/files/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | This is bold heading
8 | This is underlined paragraph
9 | This is italic heading
10 | This is new heading
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlAgilityPack.Shared.projitems.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/Metro/InvalidProgramException.cs:
--------------------------------------------------------------------------------
1 | #if METRO
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | public class InvalidProgramException : System.Exception
11 | {
12 | public InvalidProgramException(string message)
13 | : base(message)
14 | {
15 | }
16 | }
17 | }
18 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/Trace.FullFramework.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | partial class Trace
11 | {
12 | partial void WriteLineIntern(string message, string category)
13 | {
14 | System.Diagnostics.Debug.WriteLine(message, category);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("HtmlAgilityPack.Tests.fx.4.5")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("")]
9 | [assembly: AssemblyProduct("HtmlAgilityPack.Tests.fx.4.5")]
10 | [assembly: AssemblyCopyright("Copyright © 2018")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("d2276641-9ec1-4c80-a59b-4ba8e2a578aa")]
17 |
18 | // [assembly: AssemblyVersion("1.0.*")]
19 | [assembly: AssemblyVersion("1.0.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0.0")]
21 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/MixedCodeDocumentFragmentType.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 | namespace HtmlAgilityPack
10 | {
11 | ///
12 | /// Represents the type of fragment in a mixed code document.
13 | ///
14 | public enum MixedCodeDocumentFragmentType
15 | {
16 | ///
17 | /// The fragment contains code.
18 | ///
19 | Code,
20 |
21 | ///
22 | /// The fragment contains text.
23 | ///
24 | Text,
25 | }
26 | }
27 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlAgilityPack.Tests.NetStandard2_0.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 | Always
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlDocument.Xpath.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 |
10 | using System.Xml.XPath;
11 |
12 | namespace HtmlAgilityPack
13 | {
14 | public partial class HtmlDocument : IXPathNavigable
15 | {
16 | ///
17 | /// Creates a new XPathNavigator object for navigating this HTML document.
18 | ///
19 | /// An XPathNavigator object. The XPathNavigator is positioned on the root of the document.
20 | public XPathNavigator CreateNavigator()
21 | {
22 | return new HtmlNodeNavigator(this, _documentnode);
23 | }
24 | }
25 | }
26 |
27 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlWebException.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 |
10 | namespace HtmlAgilityPack
11 | {
12 | ///
13 | /// Represents an exception thrown by the HtmlWeb utility class.
14 | ///
15 | public class HtmlWebException : Exception
16 | {
17 | #region Constructors
18 |
19 | ///
20 | /// Creates an instance of the HtmlWebException.
21 | ///
22 | /// The exception's message.
23 | public HtmlWebException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | #endregion
29 | }
30 | }
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Here is what to include in your request to make sure we implement a solution as quickly as possible.
2 |
3 | ## 1. Description
4 | Describe the issue or propose a feature.
5 |
6 | ## 2. Exception
7 | If you are seeing an exception, include the full exception details (message and stack trace).
8 |
9 | ```
10 | Exception message:
11 | Stack trace:
12 | ```
13 |
14 | ## 3. Fiddle or Project
15 | If you are able,
16 |
17 | Provide a Fiddle that reproduce the issue: https://dotnetfiddle.net/25Vjsn
18 |
19 | Or provide a project/solution that we can run to reproduce the issue.
20 | - Make sure the project compile
21 | - Make sure to provide only the code that is required to reproduce the issue, not the whole project
22 | - You can send private code here: info@zzzprojects.com
23 |
24 | Otherwise, make sure to include as much information as possible to help our team to reproduce the issue.
25 |
26 | ## 4. Any further technical details
27 | Add any relevant detail can help us, such as:
28 |
29 | - HAP version:
30 | - NET version (net45, .net core 3.1, etc.)
31 |
32 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/Trace.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | internal partial class Trace
11 | {
12 | internal static Trace _current;
13 |
14 | internal static Trace Current
15 | {
16 | get
17 | {
18 | if (_current == null)
19 | _current = new Trace();
20 | return _current;
21 | }
22 | }
23 |
24 | partial void WriteLineIntern(string message, string category);
25 |
26 | public static void WriteLine(string message, string category)
27 | {
28 | Current.WriteLineIntern(message, category);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Permission is hereby granted, free of charge, to any person obtaining a copy
3 | of this software and associated documentation files (the "Software"), to deal
4 | in the Software without restriction, including without limitation the rights
5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6 | copies of the Software, and to permit persons to whom the Software is
7 | furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all
10 | copies or substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 | SOFTWARE.
19 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/EncodingFoundException.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 | using System.Text;
10 |
11 | namespace HtmlAgilityPack
12 | {
13 | internal class EncodingFoundException : Exception
14 | {
15 | #region Fields
16 |
17 | private Encoding _encoding;
18 |
19 | #endregion
20 |
21 | #region Constructors
22 |
23 | internal EncodingFoundException(Encoding encoding)
24 | {
25 | _encoding = encoding;
26 | }
27 |
28 | #endregion
29 |
30 | #region Properties
31 |
32 | internal Encoding Encoding
33 | {
34 | get { return _encoding; }
35 | }
36 |
37 | #endregion
38 | }
39 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlNodeType.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | ///
11 | /// Represents the type of a node.
12 | ///
13 | public enum HtmlNodeType
14 | {
15 | ///
16 | /// The root of a document.
17 | ///
18 | Document,
19 |
20 | ///
21 | /// An HTML element.
22 | ///
23 | Element,
24 |
25 | ///
26 | /// An HTML comment.
27 | ///
28 | Comment,
29 |
30 | ///
31 | /// A text node is always the child of an element or a document node.
32 | ///
33 | Text,
34 | }
35 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/NameValuePair.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if METRO
9 | namespace HtmlAgilityPack
10 | {
11 | internal class NameValuePair
12 | {
13 | #region Fields
14 |
15 | internal readonly string Name;
16 | internal string Value;
17 |
18 | #endregion
19 |
20 | #region Constructors
21 |
22 | internal NameValuePair()
23 | {
24 | }
25 |
26 | internal NameValuePair(string name)
27 | :
28 | this()
29 | {
30 | Name = name;
31 | }
32 |
33 | internal NameValuePair(string name, string value)
34 | :
35 | this(name)
36 | {
37 | Value = value;
38 | }
39 |
40 | #endregion
41 | }
42 | }
43 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlEntityTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | namespace HtmlAgilityPack.Tests
5 | {
6 | class HtmlEntityTest
7 | {
8 | [Test]
9 | public void Entitize_PassEmojiUnicode_ShouldCorrectlyEntitize()
10 | {
11 | try
12 | {
13 | HtmlEntity.UseWebUtility = true;
14 | string result = HtmlEntity.Entitize("😂");
15 |
16 | Assert.AreEqual("😂", result);
17 | }
18 | finally
19 | {
20 | HtmlEntity.UseWebUtility = false;
21 | }
22 |
23 | }
24 |
25 | [Test]
26 | public void Entitize_PassSimpleText_ShouldCorrectlyEntitize()
27 | {
28 | try
29 | {
30 | HtmlEntity.UseWebUtility = true;
31 | string result = HtmlEntity.Entitize("qwerty");
32 |
33 | Assert.AreEqual("qwerty", result);
34 | }
35 | finally
36 | {
37 | HtmlEntity.UseWebUtility = false;
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.UAP10/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
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: CLSCompliant(true)]
9 | [assembly: AssemblyTitle("Html Agility Pack - Release")]
10 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
11 | [assembly: AssemblyProduct("Html Agility Pack")]
12 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
13 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Version information for an assembly consists of the following four values:
17 | //
18 | // Major Version
19 | // Minor Version
20 | // Build Number
21 | // Revision
22 | //
23 | // You can specify all the values or you can default the Build and Revision Numbers
24 | // by using the '*' as shown below:
25 | // [assembly: AssemblyVersion("1.0.*")]
26 | [assembly: AssemblyVersion("1.12.4")]
27 | [assembly: AssemblyFileVersion("1.12.4")]
28 |
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlElementFlag.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 |
10 | namespace HtmlAgilityPack
11 | {
12 | ///
13 | /// Flags that describe the behavior of an Element node.
14 | ///
15 | [Flags]
16 | public enum HtmlElementFlag
17 | {
18 | ///
19 | /// The node is a CDATA node.
20 | ///
21 | CData = 1,
22 |
23 | ///
24 | /// The node is empty. META or IMG are example of such nodes.
25 | ///
26 | Empty = 2,
27 |
28 | ///
29 | /// The node will automatically be closed during parsing.
30 | ///
31 | Closed = 4,
32 |
33 | ///
34 | /// The node can overlap.
35 | ///
36 | CanOverlap = 8
37 | }
38 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/MixedCodeDocumentTextFragment.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 | namespace HtmlAgilityPack
10 | {
11 | ///
12 | /// Represents a fragment of text in a mixed code document.
13 | ///
14 | public class MixedCodeDocumentTextFragment : MixedCodeDocumentFragment
15 | {
16 | #region Constructors
17 |
18 | internal MixedCodeDocumentTextFragment(MixedCodeDocument doc)
19 | :
20 | base(doc, MixedCodeDocumentFragmentType.Text)
21 | {
22 | }
23 |
24 | #endregion
25 |
26 | #region Properties
27 |
28 | ///
29 | /// Gets the fragment text.
30 | ///
31 | public string Text
32 | {
33 | get { return FragmentText; }
34 | set { FragmentText = value; }
35 | }
36 |
37 | #endregion
38 | }
39 | }
40 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlAgilityPack.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {5BA9A0D7-173F-4C4F-AFFA-3DD6DC2F9A79}
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net7/HtmlAgilityPack.Net7.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0
5 | HtmlAgilityPack
6 | HtmlAgilityPack
7 | enable
8 | HtmlAgilityPack
9 | 1.12.4
10 | ZZZ Projects Inc.
11 | ZZZ Projects Inc.
12 | Html Agility Pack
13 | Copyright © ZZZ Projects Inc.
14 | True
15 | HtmlAgilityPack.snk
16 | True
17 |
18 |
19 |
20 | $(DefineConstants);NETSTANDARD2_0;NETSTANDARD
21 |
22 |
23 |
24 | $(DefineConstants);NETSTANDARD2_0;NETSTANDARD
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlConsoleListener.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !NETSTANDARD1_3 && !NETSTANDARD1_6 && !METRO
9 | using System;
10 | using System.Diagnostics;
11 |
12 | namespace HtmlAgilityPack
13 | {
14 | internal class HtmlConsoleListener : TraceListener
15 | {
16 | #region Public Methods
17 |
18 | public override void Write(string Message)
19 | {
20 | Write(Message, "");
21 | }
22 |
23 | public override void Write(string Message, string Category)
24 | {
25 | Console.Write("T:" + Category + ": " + Message);
26 | }
27 |
28 | public override void WriteLine(string Message)
29 | {
30 | Write(Message + "\n");
31 | }
32 |
33 | public override void WriteLine(string Message, string Category)
34 | {
35 | Write(Message + "\n", Category);
36 | }
37 |
38 | #endregion
39 | }
40 | }
41 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlParseErrorCode.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | ///
11 | /// Represents the type of parsing error.
12 | ///
13 | public enum HtmlParseErrorCode
14 | {
15 | ///
16 | /// A tag was not closed.
17 | ///
18 | TagNotClosed,
19 |
20 | ///
21 | /// A tag was not opened.
22 | ///
23 | TagNotOpened,
24 |
25 | ///
26 | /// There is a charset mismatch between stream and declared (META) encoding.
27 | ///
28 | CharsetMismatch,
29 |
30 | ///
31 | /// An end tag was not required.
32 | ///
33 | EndTagNotRequired,
34 |
35 | ///
36 | /// An end tag is invalid at this position.
37 | ///
38 | EndTagInvalidHere
39 | }
40 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/IOLibrary.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 | using System.IO;
10 |
11 | namespace HtmlAgilityPack
12 | {
13 | internal struct IOLibrary
14 | {
15 | #region Internal Methods
16 |
17 | internal static void CopyAlways(string source, string target)
18 | {
19 | if (!File.Exists(source))
20 | return;
21 | Directory.CreateDirectory(Path.GetDirectoryName(target));
22 | MakeWritable(target);
23 | File.Copy(source, target, true);
24 | }
25 | #if !PocketPC && !WINDOWS_PHONE
26 | internal static void MakeWritable(string path)
27 | {
28 | if (!File.Exists(path))
29 | return;
30 | File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
31 | }
32 | #else
33 | internal static void MakeWritable(string path)
34 | {
35 | }
36 | #endif
37 | #endregion
38 | }
39 | }
40 |
41 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlNameTable.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System.Xml;
9 |
10 | namespace HtmlAgilityPack
11 | {
12 | internal sealed class HtmlNameTable : XmlNameTable
13 | {
14 | #region Fields
15 |
16 | private NameTable _nametable = new NameTable();
17 |
18 | #endregion
19 |
20 | #region Public Methods
21 |
22 | public override string Add(string array)
23 | {
24 | return _nametable.Add(array);
25 | }
26 |
27 | public override string Add(char[] array, int offset, int length)
28 | {
29 | return _nametable.Add(array, offset, length);
30 | }
31 |
32 | public override string Get(string array)
33 | {
34 | return _nametable.Get(array);
35 | }
36 |
37 | public override string Get(char[] array, int offset, int length)
38 | {
39 | return _nametable.Get(array, offset, length);
40 | }
41 |
42 | #endregion
43 |
44 | #region Internal Methods
45 |
46 | internal string GetOrAdd(string array)
47 | {
48 | string s = Get(array);
49 | if (s == null)
50 | {
51 | return Add(array);
52 | }
53 |
54 | return s;
55 | }
56 |
57 | #endregion
58 | }
59 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NETStandard2_0/HtmlAgilityPack.NETStandard2_0.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | netstandard2.0
12 | HtmlAgilityPack
13 | HtmlAgilityPack
14 | HtmlAgilityPack
15 | 1.12.4
16 | ZZZ Projects Inc.
17 | ZZZ Projects Inc.
18 | Html Agility Pack
19 | Copyright © ZZZ Projects Inc.
20 | true
21 | HtmlAgilityPack.snk
22 |
23 |
24 |
25 | TRACE;RELEASE;NETSTANDARD2_0;NETSTANDARD
26 | bin\Release\netstandard2.0\HtmlAgilityPack.xml
27 | bin\Release\netstandard2.0\
28 |
29 |
30 |
31 | TRACE;DEBUG;NETSTANDARD2_0;NETSTANDARD
32 | bin\Debug\netstandard2.0\
33 | bin\Debug\netstandard2.0\HtmlAgilityPack.xml
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetStandard1_6/HtmlAgilityPack.NetStandard1_6.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | netstandard1.6
12 | True
13 | HtmlAgilityPack.snk
14 | HtmlAgilityPack
15 | 1.11.74
16 | Copyright © ZZZ Projects Inc.
17 | ZZZ Projects Inc.
18 | Html Agility Pack
19 |
20 | ZZZ Projects Inc.
21 |
22 |
23 |
24 | TRACE;DEBUG;NETSTANDARD;NETSTANDARD1_6
25 | bin\Debug\netstandard1.6\
26 | bin\Debug\netstandard1.6\HtmlAgilityPack.xml
27 |
28 |
29 |
30 | TRACE;NETSTANDARD;NETSTANDARD1_6
31 | bin\Release\netstandard1.6\HtmlAgilityPack.xml
32 | bin\Release\netstandard1.6\
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NETStandard1_3/HtmlAgilityPack.NETStandard1_3.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | netstandard1.3
12 | HtmlAgilityPack
13 | 1.11.74
14 | ZZZ Projects Inc.
15 | ZZZ Projects Inc.
16 | Html Agility Pack
17 | Copyright © ZZZ Projects Inc.
18 | True
19 | HtmlAgilityPack.snk
20 | HtmlAgilityPack
21 |
22 |
23 |
24 | TRACE;DEBUG;NETSTANDARD;NETSTANDARD1_3
25 | bin\Debug\netstandard1.3\HtmlAgilityPack.xml
26 | bin\Debug\netstandard1.3\
27 |
28 |
29 |
30 | TRACE;NETSTANDARD;NETSTANDARD1_3
31 | bin\Release\netstandard1.3\HtmlAgilityPack.xml
32 | bin\Release\netstandard1.3\
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/MixedCodeDocumentCodeFragment.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 | namespace HtmlAgilityPack
10 | {
11 | ///
12 | /// Represents a fragment of code in a mixed code document.
13 | ///
14 | public class MixedCodeDocumentCodeFragment : MixedCodeDocumentFragment
15 | {
16 | #region Fields
17 |
18 | private string _code;
19 |
20 | #endregion
21 |
22 | #region Constructors
23 |
24 | internal MixedCodeDocumentCodeFragment(MixedCodeDocument doc)
25 | :
26 | base(doc, MixedCodeDocumentFragmentType.Code)
27 | {
28 | }
29 |
30 | #endregion
31 |
32 | #region Properties
33 |
34 | ///
35 | /// Gets the fragment code text.
36 | ///
37 | public string Code
38 | {
39 | get
40 | {
41 | if (_code == null)
42 | {
43 | _code = FragmentText.Substring(Doc.TokenCodeStart.Length,
44 | FragmentText.Length - Doc.TokenCodeEnd.Length -
45 | Doc.TokenCodeStart.Length - 1).Trim();
46 | if (_code.StartsWith("="))
47 | {
48 | _code = Doc.TokenResponseWrite + _code.Substring(1, _code.Length - 1);
49 | }
50 | }
51 |
52 | return _code;
53 | }
54 | set { _code = value; }
55 | }
56 |
57 | #endregion
58 | }
59 | }
60 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net35/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net45/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40-client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetCore45/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp8/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp81/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Security;
6 |
7 | [assembly: CLSCompliant(true)]
8 | #if DEBUG
9 | // Assembly marked as compliant.
10 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
11 | #else // release
12 | #if TRACE
13 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
14 | #else
15 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
16 | #endif
17 | #endif
18 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
19 | [assembly: AssemblyConfiguration("")]
20 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
21 | [assembly: AssemblyProduct("Html Agility Pack")]
22 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
23 | [assembly: AssemblyTrademark("ZZZ Projects Inc.")]
24 | [assembly: AssemblyCulture("")]
25 | [assembly: ComVisible(true)]
26 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
27 | [assembly: AssemblyVersion("1.12.4")]
28 | #if !PocketPC
29 | [assembly: AssemblyFileVersion("1.12.4")]
30 | [assembly: AssemblyInformationalVersion("1.12.4")]
31 | #if !SILVERLIGHT
32 | [assembly: AllowPartiallyTrustedCallers]
33 | #endif
34 | [assembly: AssemblyDelaySign(false)]
35 | #endif
36 | //
37 | // Welcome to the HTML Agility Pack!
38 | // As you may have noticed, there is no HtmlAgilityPack file provided.
39 | // You need to build one using SN.EXE utility provided with the .NET Framework
40 | //
41 | // The command to use is something like:
42 | // SN.EXE -k HtmlAgilityPack.snk
43 | //
44 | //
45 |
46 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/files/overflow.html:
--------------------------------------------------------------------------------
1 | User list - XCC Forum
2 |
3 |
4 | | X
5 | | |
6 | X
7 | | X
8 | | X
9 | | X
10 | |
11 | | X
12 | | X
13 | | X
14 | | X
15 | | X
16 | | X
17 | |
18 | | X
19 | | X
20 | | X
21 | | X
22 | | X
23 | | X
24 | |
25 | | X
26 | | X
27 | | X
28 | | X
29 | | X
30 | | X
31 | |
32 | | X
33 | | X
34 | | X
35 | | X
36 | | X
37 | | X
38 | |
39 | | X
40 | | X
41 | | X
42 | | X
43 | | X
44 | | X
45 | |
46 | | X
47 | | X
48 | | X
49 | | X
50 | | X
51 | | X
52 | |
53 | | X
54 | | X
55 | | X
56 | | X
57 | | X
58 | | X
59 | |
60 | | X
61 | | X
62 | | X
63 | | X
64 | | X
65 | | X
66 | |
67 | | X
68 | | X
69 | | X
70 | | X
71 | | X
72 | | X
73 | |
74 | | X
75 | | X
76 | | X
77 | | X
78 | | X
79 | | X
80 | |
81 | | X
82 | | X
83 | | X |
84 | | X
85 | | X
86 | | X
87 | |
88 | | X
89 | | X
90 | | X
91 | | X
92 | | X
93 | | X
94 | |
95 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net20/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // HtmlAgilityPack V1.0 - Simon Mourier
2 |
3 | using System;
4 | using System.Reflection;
5 | using System.Runtime.CompilerServices;
6 | using System.Runtime.InteropServices;
7 | using System.Security;
8 |
9 | [assembly: CLSCompliant(true)]
10 | #if DEBUG
11 | // Assembly marked as compliant.
12 | [assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
13 | #else // release
14 | #if TRACE
15 | [assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
16 | #else
17 | [assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
18 | #endif
19 | #endif
20 | [assembly: InternalsVisibleTo("HtmlAgilityPack.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010027dc71d8e0b968c7324238e18a4cee4a367f1bf50c9d7a52d91ed46c6a1a584b9142c1d4234c4011d25437c909924079660c434eebe6d2c46412f30520a276e7ca8d8fa7075bb8b9e1c7502ef0e50423b32d469ba750012823fde16989ab42d8428ca5fdd0b06b801788a17239b78e0f75900012a50c5038ab93abbe2ac0d6ee")]
21 | [assembly: AssemblyConfiguration("")]
22 | [assembly: AssemblyCompany("ZZZ Projects Inc.")]
23 | [assembly: AssemblyProduct("Html Agility Pack")]
24 | [assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc.")]
25 | [assembly: AssemblyTrademark("SQL & .NET Tools")]
26 | [assembly: AssemblyCulture("")]
27 | [assembly: ComVisible(true)]
28 | [assembly: Guid("643622ea-d2aa-4572-a2b2-6202b7fcd83f")]
29 | [assembly: AssemblyVersion("1.11.16")]
30 | #if !PocketPC
31 | [assembly: AssemblyFileVersion("1.11.16")]
32 | [assembly: AssemblyInformationalVersion("1.11.16")]
33 | #if !SILVERLIGHT
34 | [assembly: AllowPartiallyTrustedCallers]
35 | #endif
36 | [assembly: AssemblyDelaySign(false)]
37 | #endif
38 | //
39 | // Welcome to the HTML Agility Pack!
40 | // As you may have noticed, there is no HtmlAgilityPack file provided.
41 | // You need to build one using SN.EXE utility provided with the .NET Framework
42 | //
43 | // The command to use is something like:
44 | // SN.EXE -k HtmlAgilityPack.snk
45 | //
46 | // Simon.
47 | //
48 |
49 | [assembly: AssemblyKeyName("")]
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/files/attr_quote_expected.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/files/attr_quote_expected.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlTextNode.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | ///
11 | /// Represents an HTML text node.
12 | ///
13 | public class HtmlTextNode : HtmlNode
14 | {
15 | #region Fields
16 |
17 | private string _text;
18 |
19 | #endregion
20 |
21 | #region Constructors
22 |
23 | internal HtmlTextNode(HtmlDocument ownerdocument, int index)
24 | :
25 | base(HtmlNodeType.Text, ownerdocument, index)
26 | {
27 | }
28 |
29 | #endregion
30 |
31 | #region Properties
32 |
33 | ///
34 | /// Gets or Sets the HTML between the start and end tags of the object. In the case of a text node, it is equals to OuterHtml.
35 | ///
36 | public override string InnerHtml
37 | {
38 | get { return OuterHtml; }
39 | set { _text = value; }
40 | }
41 |
42 | ///
43 | /// Gets or Sets the object and its content in HTML.
44 | ///
45 | public override string OuterHtml
46 | {
47 | get
48 | {
49 | if (_text == null)
50 | {
51 | return base.OuterHtml;
52 | }
53 |
54 | return _text;
55 | }
56 | }
57 |
58 | ///
59 | /// Gets or Sets the text of the node.
60 | ///
61 | public string Text
62 | {
63 | get
64 | {
65 | if (_text == null)
66 | {
67 | return base.OuterHtml;
68 | }
69 |
70 | return _text;
71 | }
72 | set
73 | {
74 | _text = value;
75 | SetChanged();
76 | }
77 | }
78 |
79 | #endregion
80 | }
81 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/InvalidProgramException.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if METRO
9 |
10 | using System.Runtime.InteropServices;
11 |
12 | namespace System
13 | {
14 | ///
15 | /// The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.
16 | ///
17 | /// 2
18 | [ComVisible(true)]
19 | public sealed class InvalidProgramException : Exception
20 | {
21 | ///
22 | /// Initializes a new instance of the class with default properties.
23 | ///
24 | public InvalidProgramException()
25 | {
26 | }
27 |
28 | ///
29 | /// Initializes a new instance of the class with a specified error message.
30 | ///
31 | /// The error message that explains the reason for the exception.
32 | public InvalidProgramException(string message) : base(message)
33 | {
34 | }
35 |
36 | ///
37 | /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.
38 | ///
39 | /// The error message that explains the reason for the exception. The exception that is the cause of the current exception. If the parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception.
40 | public InvalidProgramException(string message, Exception inner) : base(message, inner)
41 | {
42 | }
43 | }
44 | }
45 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/Utilities.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.ComponentModel;
11 |
12 | namespace HtmlAgilityPack
13 | {
14 | internal static class Utilities
15 | {
16 | public static
17 | #if NET8_0
18 | TValue?
19 | #else
20 | TValue
21 | #endif
22 | GetDictionaryValueOrDefault(Dictionary dict, TKey key, TValue defaultValue = default(TValue)) where TKey : class
23 | {
24 | TValue value;
25 | if (!dict.TryGetValue(key, out value))
26 | return defaultValue;
27 | return value;
28 | }
29 |
30 | #if !(METRO || NETSTANDARD1_3 || NETSTANDARD1_6)
31 | internal static object To(this Object @this, Type type)
32 | {
33 | if (@this != null)
34 | {
35 | Type targetType = type;
36 |
37 | if (@this.GetType() == targetType)
38 | {
39 | return @this;
40 | }
41 |
42 | TypeConverter converter = TypeDescriptor.GetConverter(@this);
43 | if (converter != null)
44 | {
45 | if (converter.CanConvertTo(targetType))
46 | {
47 | return converter.ConvertTo(@this, targetType);
48 | }
49 | }
50 |
51 | converter = TypeDescriptor.GetConverter(targetType);
52 | if (converter != null)
53 | {
54 | if (converter.CanConvertFrom(@this.GetType()))
55 | {
56 | return converter.ConvertFrom(@this);
57 | }
58 | }
59 |
60 | if (@this == DBNull.Value)
61 | {
62 | return null;
63 | }
64 | }
65 |
66 | return @this;
67 | }
68 | #endif
69 | }
70 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Html Agility Pack
2 |
3 | Html Agility Pack (HAP) It is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (No need to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant of "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
4 |
5 | Read more on our [Website](https://html-agility-pack.net/).
6 |
7 | ## Downloads
8 |
9 | [](https://www.nuget.org/packages/HtmlAgilityPack)
10 | [](https://www.nuget.org/packages/HtmlAgilityPack)
11 |
12 | ```
13 | PM> NuGet\Install-Package HtmlAgilityPack
14 | ```
15 |
16 | ```
17 | PM> dotnet add package HtmlAgilityPack
18 | ```
19 |
20 | ## Sponsors
21 |
22 | ZZZ Projects owns and maintains **Html Agility Pack** as part of our [mission](https://zzzprojects.com/mission) to add value to the .NET community
23 |
24 | Through [Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=zzzprojects&utm_medium=htmlagilitypack) and [Dapper Plus](https://dapper-plus.net/?utm_source=zzzprojects&utm_medium=htmlagilitypack), we actively sponsor and help key open-source libraries grow.
25 |
26 | [](https://entityframework-extensions.net/bulk-insert?utm_source=zzzprojects&utm_medium=htmlagilitypack)
27 |
28 | [](https://dapper-plus.net/bulk-insert?utm_source=zzzprojects&utm_medium=htmlagilitypack)
29 |
30 | ## More Projects
31 |
32 | - Projects:
33 | - [EntityFramework Extensions](https://entityframework-extensions.net/)
34 | - [Dapper Plus](https://dapper-plus.net/)
35 | - [C# Eval Expression](https://eval-expression.net/)
36 | - Learn Websites
37 | - [Learn EF Core](https://www.learnentityframeworkcore.com/)
38 | - [Learn Dapper](https://www.learndapper.com/)
39 | - Online Tools:
40 | - [.NET Fiddle](https://dotnetfiddle.net/)
41 | - [SQL Fiddle](https://sqlfiddle.com/)
42 | - [ZZZ Code AI](https://zzzcode.ai/)
43 | - and much more!
44 |
45 | To view all our free and paid projects, visit our website [ZZZ Projects](https://zzzprojects.com/).
46 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/files/attr_quote.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
20 |
21 |
22 | {{ 'Lea.Cotacoes.Simulador.CodCategoriaBem' | translate}}
23 |
24 |
27 |
28 |
29 |
30 | {{ dimension.code }} - {{ dimension.description }}
31 |
32 |
33 | {{ simulationRequest.categoriaBemId | commonData:lea546CATBEM$:'id':'code-desc' }}
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/files/attr_quote.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
20 |
21 |
22 | {{ 'Lea.Cotacoes.Simulador.CodCategoriaBem' | translate}}
23 |
24 |
27 |
28 |
29 |
30 | {{ dimension.code }} - {{ dimension.description }}
31 |
32 |
33 | {{ simulationRequest.categoriaBemId | commonData:lea546CATBEM$:'id':'code-desc' }}
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlCommentNode.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | ///
11 | /// Represents an HTML comment.
12 | ///
13 | public class HtmlCommentNode : HtmlNode
14 | {
15 | #region Fields
16 |
17 | private string _comment;
18 |
19 | #endregion
20 |
21 | #region Constructors
22 |
23 | internal HtmlCommentNode(HtmlDocument ownerdocument, int index)
24 | :
25 | base(HtmlNodeType.Comment, ownerdocument, index)
26 | {
27 | }
28 |
29 | #endregion
30 |
31 | #region Properties
32 |
33 | ///
34 | /// Gets or Sets the comment text of the node.
35 | ///
36 | public string Comment
37 | {
38 | get
39 | {
40 | if (_comment == null)
41 | {
42 | return base.InnerHtml;
43 | }
44 |
45 | return _comment;
46 | }
47 | set { _comment = value; }
48 | }
49 |
50 | ///
51 | /// Gets or Sets the HTML between the start and end tags of the object. In the case of a text node, it is equals to OuterHtml.
52 | ///
53 | public override string InnerHtml
54 | {
55 | get
56 | {
57 | if (_comment == null)
58 | {
59 | return base.InnerHtml;
60 | }
61 |
62 | return _comment;
63 | }
64 | set { _comment = value; }
65 | }
66 |
67 | ///
68 | /// Gets or Sets the object and its content in HTML.
69 | ///
70 | public override string OuterHtml
71 | {
72 | get
73 | {
74 | if (_comment == null)
75 | {
76 | return base.OuterHtml;
77 | }
78 |
79 | if(_comment.StartsWith(""))
80 | {
81 | return _comment;
82 | }
83 |
84 | return "";
85 | }
86 | }
87 |
88 | #endregion
89 | }
90 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net35/HtmlAgilityPack.Net35.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {BA2F3BE3-D811-469A-A291-41D6F6F35F7F}
8 | Library
9 | Properties
10 | HtmlAgilityPack
11 | HtmlAgilityPack
12 | v3.5
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | TRACE;DEBUG;FX35
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE;FX35
30 | prompt
31 | 4
32 | bin\Release\HtmlAgilityPack.xml
33 |
34 |
35 | true
36 |
37 |
38 | HtmlAgilityPack.snk
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.NetCore45/HtmlAgilityPack.NetCore45.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | 8.0.30703
8 | 2.0
9 | {91599A41-D512-44B6-BFB0-6B8748E3BB0E}
10 | Library
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | Profile111
14 | v4.5
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug
29 | DEBUG;METRO
30 | prompt
31 | 4
32 | false
33 |
34 |
35 | full
36 | true
37 | bin\Release
38 | prompt
39 | 4
40 | false
41 | METRO
42 | bin\Release\HtmlAgilityPack.XML
43 |
44 |
45 | true
46 |
47 |
48 | HtmlAgilityPack.snk
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp8/HtmlAgilityPack.Portable-wp8.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | 8.0.30703
8 | 2.0
9 | {56BB5DD2-1BA9-42E0-A449-8FB84DA95C6E}
10 | Library
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | Profile111
14 | v4.5
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug
29 | DEBUG;METRO
30 | prompt
31 | 4
32 | false
33 | bin\Debug\HtmlAgilityPack.XML
34 |
35 |
36 | full
37 | true
38 | bin\Release
39 | prompt
40 | 4
41 | false
42 | METRO
43 | bin\Release\HtmlAgilityPack.XML
44 |
45 |
46 | true
47 |
48 |
49 | HtmlAgilityPack.snk
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Portable-wp81/HtmlAgilityPack.Portable-wp81.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | 8.0.30703
8 | 2.0
9 | {49677C78-8F68-41D1-8DA6-3E91BD44AC57}
10 | Library
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | Profile111
14 | v4.5
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug
29 | DEBUG;METRO
30 | prompt
31 | 4
32 | false
33 | bin\Debug\HtmlAgilityPack.XML
34 |
35 |
36 | full
37 | true
38 | bin\Release
39 | prompt
40 | 4
41 | false
42 | METRO
43 | bin\Release\HtmlAgilityPack.XML
44 |
45 |
46 | true
47 |
48 |
49 | HtmlAgilityPack.snk
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlParseError.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | namespace HtmlAgilityPack
9 | {
10 | ///
11 | /// Represents a parsing error found during document parsing.
12 | ///
13 | public class HtmlParseError
14 | {
15 | #region Fields
16 |
17 | private HtmlParseErrorCode _code;
18 | private int _line;
19 | private int _linePosition;
20 | private string _reason;
21 | private string _sourceText;
22 | private int _streamPosition;
23 |
24 | #endregion
25 |
26 | #region Constructors
27 |
28 | internal HtmlParseError(
29 | HtmlParseErrorCode code,
30 | int line,
31 | int linePosition,
32 | int streamPosition,
33 | string sourceText,
34 | string reason)
35 | {
36 | _code = code;
37 | _line = line;
38 | _linePosition = linePosition;
39 | _streamPosition = streamPosition;
40 | _sourceText = sourceText;
41 | _reason = reason;
42 | }
43 |
44 | #endregion
45 |
46 | #region Properties
47 |
48 | ///
49 | /// Gets the type of error.
50 | ///
51 | public HtmlParseErrorCode Code
52 | {
53 | get { return _code; }
54 | }
55 |
56 | ///
57 | /// Gets the line number of this error in the document.
58 | ///
59 | public int Line
60 | {
61 | get { return _line; }
62 | }
63 |
64 | ///
65 | /// Gets the column number of this error in the document.
66 | ///
67 | public int LinePosition
68 | {
69 | get { return _linePosition; }
70 | }
71 |
72 | ///
73 | /// Gets a description for the error.
74 | ///
75 | public string Reason
76 | {
77 | get { return _reason; }
78 | }
79 |
80 | ///
81 | /// Gets the the full text of the line containing the error.
82 | ///
83 | public string SourceText
84 | {
85 | get { return _sourceText; }
86 | }
87 |
88 | ///
89 | /// Gets the absolute stream position of this error in the document, relative to the start of the document.
90 | ///
91 | public int StreamPosition
92 | {
93 | get { return _streamPosition; }
94 | }
95 |
96 | #endregion
97 | }
98 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/MixedCodeDocumentFragment.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 | namespace HtmlAgilityPack
10 | {
11 | ///
12 | /// Represents a base class for fragments in a mixed code document.
13 | ///
14 | public abstract class MixedCodeDocumentFragment
15 | {
16 | #region Fields
17 |
18 | internal MixedCodeDocument Doc;
19 | private string _fragmentText;
20 | internal int Index;
21 | internal int Length;
22 | private int _line;
23 | internal int _lineposition;
24 | internal MixedCodeDocumentFragmentType _type;
25 |
26 | #endregion
27 |
28 | #region Constructors
29 |
30 | internal MixedCodeDocumentFragment(MixedCodeDocument doc, MixedCodeDocumentFragmentType type)
31 | {
32 | Doc = doc;
33 | _type = type;
34 | switch (type)
35 | {
36 | case MixedCodeDocumentFragmentType.Text:
37 | Doc._textfragments.Append(this);
38 | break;
39 |
40 | case MixedCodeDocumentFragmentType.Code:
41 | Doc._codefragments.Append(this);
42 | break;
43 | }
44 |
45 | Doc._fragments.Append(this);
46 | }
47 |
48 | #endregion
49 |
50 | #region Properties
51 |
52 | ///
53 | /// Gets the fragement text.
54 | ///
55 | public string FragmentText
56 | {
57 | get
58 | {
59 | if (_fragmentText == null)
60 | {
61 | _fragmentText = Doc._text.Substring(Index, Length);
62 | }
63 |
64 | return _fragmentText;
65 | }
66 | internal set { _fragmentText = value; }
67 | }
68 |
69 | ///
70 | /// Gets the type of fragment.
71 | ///
72 | public MixedCodeDocumentFragmentType FragmentType
73 | {
74 | get { return _type; }
75 | }
76 |
77 | ///
78 | /// Gets the line number of the fragment.
79 | ///
80 | public int Line
81 | {
82 | get { return _line; }
83 | internal set { _line = value; }
84 | }
85 |
86 | ///
87 | /// Gets the line position (column) of the fragment.
88 | ///
89 | public int LinePosition
90 | {
91 | get { return _lineposition; }
92 | }
93 |
94 | ///
95 | /// Gets the fragment position in the document's stream.
96 | ///
97 | public int StreamPosition
98 | {
99 | get { return Index; }
100 | }
101 |
102 | #endregion
103 | }
104 | }
105 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/EncapsulationTestHtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 |
5 | namespace HtmlAgilityPack.Tests.NetStandard2_0
6 | {
7 | [HasXPath]
8 | [DebuggerDisplay("{Title}")]
9 | public class EncapsulationTestHtml
10 | {
11 | public const string Html = @"
12 |
13 |
14 | Test
15 |
16 |
17 | Test
18 | Link 1
19 | Link 2
20 | Link 3
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | 3 seconds ago
32 | Content 1
33 |
34 |
35 |
36 | Content 2
37 |
38 | ";
39 | [XPath("//head/title")]
40 | public string Title { get; set; } = null!;
41 |
42 | [XPath("//h1")]
43 | public string H1 { get; set; } = null!;
44 |
45 | [XPath("//a[@class='link'][1]")]
46 | public string Link1 { get; set; } = null!;
47 |
48 | [XPath("//a[@class='link'][2]")]
49 | [SkipNodeNotFound]
50 | public string? Link2 { get; set; }
51 |
52 | [XPath("//a[@class='link'][3]", ReturnType.OuterHtml)]
53 | [SkipNodeNotFound]
54 | public Link? Link3 { get; set; }
55 |
56 | [XPath("//div/form")]
57 | public FormName? Form { get; set; }
58 |
59 | [XPath("//article", ReturnType.OuterHtml)]
60 | public List Articles { get; set; } = new List();
61 |
62 | [HasXPath]
63 | [DebuggerDisplay("{Text}/{Href}")]
64 | public class Link
65 | {
66 | [XPath("a")]
67 | public string Text { get; set; } = null!;
68 |
69 | [XPath("a", "href")]
70 | public string Href { get; set; } = null!;
71 | }
72 |
73 | [HasXPath]
74 | [DebuggerDisplay("{UserName}")]
75 | public class FormName
76 | {
77 | [XPath("input[1]", "name")]
78 | public string UserName { get; set; } = null!;
79 |
80 | [XPath("input[2]", "name")]
81 | public string Password { get; set; } = null!;
82 | [XPath("input[3]", "name")]
83 | public string Email { get; set; } = null!;
84 | [XPath("input[4]", "name")]
85 | public string Email2 { get; set; } = null!;
86 | }
87 |
88 |
89 | [HasXPath]
90 | [DebuggerDisplay("{Id}/{Title}")]
91 | public class Article
92 | {
93 | [XPath("article", "id")]
94 | public string Id { get; set; } = null!;
95 | [XPath("article/h2/a", ReturnType.OuterHtml)]
96 | public Link Title { get; set; } = null!;
97 |
98 | [XPath("article/div/span", "title")]
99 | [SkipNodeNotFound]
100 | public DateTime Created { get; set; }
101 |
102 | [XPath("article/div/span")]
103 | [SkipNodeNotFound]
104 | public string? CreatedText { get; set; } = null!;
105 | [XPath("article/p")]
106 | public string? Content { get; set; }
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net20/HtmlAgilityPack.Net20.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {193BB801-054F-4729-9D5D-FCE1E32594BF}
9 | Library
10 | Properties
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | true
14 | HtmlAgilityPack.snk
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 |
21 | 3.5
22 |
23 |
24 | v2.0
25 | publish\
26 | true
27 | Disk
28 | false
29 | Foreground
30 | 7
31 | Days
32 | false
33 | false
34 | true
35 | 0
36 | 1.0.0.%2a
37 | false
38 | false
39 | true
40 |
41 |
42 | true
43 | full
44 | false
45 | bin\Debug\
46 | TRACE;DEBUG;FX20
47 | prompt
48 | 4
49 | bin\Debug\HtmlAgilityPack.xml
50 | AllRules.ruleset
51 |
52 |
53 | pdbonly
54 | true
55 | bin\Release\
56 | FX20
57 | prompt
58 | 4
59 | bin\Release\HtmlAgilityPack.xml
60 | AllRules.ruleset
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40-client/HtmlAgilityPack.Net40-client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {28FD0302-1475-49B0-AE56-7712449D2EAF}
9 | Library
10 | Properties
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | true
14 | HtmlAgilityPack.snk
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | 3.5
26 |
27 |
28 | v4.0
29 | publish\
30 | true
31 | Disk
32 | false
33 | Foreground
34 | 7
35 | Days
36 | false
37 | false
38 | true
39 | 0
40 | 1.0.0.%2a
41 | false
42 | false
43 | true
44 | Client
45 |
46 |
47 | true
48 | full
49 | false
50 | bin\Debug\
51 | DEBUG;TRACE
52 | prompt
53 | 4
54 | bin\Debug\HtmlAgilityPack.XML
55 | AllRules.ruleset
56 |
57 |
58 | pdbonly
59 | true
60 | bin\Release\
61 | FX40
62 | prompt
63 | 4
64 | bin\Release\HtmlAgilityPack.xml
65 | AllRules.ruleset
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net40/HtmlAgilityPack.Net40.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {1028002A-BBE2-4FF2-94B7-A8368A8F6887}
9 | Library
10 | Properties
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | true
14 | HtmlAgilityPack.snk
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | 3.5
26 |
27 |
28 | v4.0
29 | publish\
30 | true
31 | Disk
32 | false
33 | Foreground
34 | 7
35 | Days
36 | false
37 | false
38 | true
39 | 0
40 | 1.0.0.%2a
41 | false
42 | false
43 | true
44 |
45 |
46 |
47 | true
48 | full
49 | false
50 | bin\Debug\
51 | TRACE;DEBUG;FX40
52 | prompt
53 | 4
54 | bin\Debug\HtmlAgilityPack.xml
55 | AllRules.ruleset
56 |
57 |
58 | pdbonly
59 | true
60 | bin\Release\
61 | FX40
62 | prompt
63 | 4
64 | bin\Release\HtmlAgilityPack.XML
65 | AllRules.ruleset
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/NameValuePairList.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 | using System.Collections.Generic;
10 |
11 | namespace HtmlAgilityPack
12 | {
13 | internal class NameValuePairList
14 | {
15 | #region Fields
16 |
17 | internal readonly string Text;
18 | private List> _allPairs;
19 | private Dictionary>> _pairsWithName;
20 |
21 | #endregion
22 |
23 | #region Constructors
24 |
25 | internal NameValuePairList() :
26 | this(null)
27 | {
28 | }
29 |
30 | internal NameValuePairList(string text)
31 | {
32 | Text = text;
33 | _allPairs = new List>();
34 | _pairsWithName = new Dictionary>>();
35 |
36 | Parse(text);
37 | }
38 |
39 | #endregion
40 |
41 | #region Internal Methods
42 |
43 | internal static string GetNameValuePairsValue(string text, string name)
44 | {
45 | NameValuePairList l = new NameValuePairList(text);
46 | return l.GetNameValuePairValue(name);
47 | }
48 |
49 | internal List> GetNameValuePairs(string name)
50 | {
51 | if (name == null)
52 | return _allPairs;
53 |
54 | return _pairsWithName.TryGetValue(name, out List> value)
55 | ? value
56 | : new List>();
57 | }
58 |
59 | internal string GetNameValuePairValue(string name)
60 | {
61 | if (name == null)
62 | throw new ArgumentNullException();
63 | List> al = GetNameValuePairs(name);
64 | if (al.Count == 0)
65 | return string.Empty;
66 |
67 | // return first item
68 | return al[0].Value.Trim();
69 | }
70 |
71 | #endregion
72 |
73 | #region Private Methods
74 |
75 | private void Parse(string text)
76 | {
77 | _allPairs.Clear();
78 | _pairsWithName.Clear();
79 | if (text == null)
80 | return;
81 |
82 | string[] p = text.Split(';');
83 | foreach (string pv in p)
84 | {
85 | if (pv.Length == 0)
86 | continue;
87 | string[] onep = pv.Split(new[] {'='}, 2);
88 | if (onep.Length == 0)
89 | continue;
90 | KeyValuePair nvp = new KeyValuePair(onep[0].Trim().ToLowerInvariant(),
91 | onep.Length < 2 ? "" : onep[1]);
92 |
93 | _allPairs.Add(nvp);
94 |
95 | // index by name
96 | List> al;
97 | if (!_pairsWithName.TryGetValue(nvp.Key, out al))
98 | {
99 | al = new List>();
100 | _pairsWithName.Add(nvp.Key, al);
101 | }
102 |
103 | al.Add(nvp);
104 | }
105 | }
106 |
107 | #endregion
108 | }
109 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Net45/HtmlAgilityPack.Net45.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {8DCFDE1C-263F-41D4-B518-9B7EE06F7D52}
9 | Library
10 | Properties
11 | HtmlAgilityPack
12 | HtmlAgilityPack
13 | true
14 | HtmlAgilityPack.snk
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | 3.5
26 |
27 |
28 | v4.5
29 | publish\
30 | true
31 | Disk
32 | false
33 | Foreground
34 | 7
35 | Days
36 | false
37 | false
38 | true
39 | 0
40 | 1.0.0.%2a
41 | false
42 | false
43 | true
44 |
45 |
46 |
47 | true
48 | full
49 | false
50 | bin\Debug\
51 | TRACE;DEBUG;FX40 FX45
52 | prompt
53 | 4
54 | bin\Debug\HtmlAgilityPack.XML
55 | AllRules.ruleset
56 | false
57 |
58 |
59 | pdbonly
60 | true
61 | bin\Release\
62 | FX40 FX45
63 | prompt
64 | 4
65 | bin\Release\HtmlAgilityPack.XML
66 | AllRules.ruleset
67 | false
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlAgilityPack.Shared.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {766aa8be-d147-4e89-a3de-51c383456f20}
5 | SAK
6 | SAK
7 | SAK
8 | SAK
9 |
10 |
11 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
12 | true
13 | f1d90ca4-d7c4-43ea-852f-fb4ab5f3a600
14 |
15 |
16 | HtmlAgilityPack.Shared
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlCmdLine.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 |
10 | #if !NETSTANDARD1_3 && !METRO
11 | namespace HtmlAgilityPack
12 | {
13 | internal class HtmlCmdLine
14 | {
15 | #region Static Members
16 |
17 | internal static bool Help;
18 |
19 | #endregion
20 |
21 | #region Constructors
22 |
23 | static HtmlCmdLine()
24 | {
25 | Help = false;
26 | ParseArgs();
27 | }
28 |
29 | #endregion
30 |
31 | #region Internal Methods
32 |
33 | internal static string GetOption(string name, string def)
34 | {
35 | string p = def;
36 | string[] args = Environment.GetCommandLineArgs();
37 | for (int i = 1; i < args.Length; i++)
38 | {
39 | GetStringArg(args[i], name, ref p);
40 | }
41 |
42 | return p;
43 | }
44 |
45 | internal static string GetOption(int index, string def)
46 | {
47 | string p = def;
48 | string[] args = Environment.GetCommandLineArgs();
49 | int j = 0;
50 | for (int i = 1; i < args.Length; i++)
51 | {
52 | if (GetStringArg(args[i], ref p))
53 | {
54 | if (index == j)
55 | return p;
56 | else
57 | p = def;
58 | j++;
59 | }
60 | }
61 |
62 | return p;
63 | }
64 |
65 | internal static bool GetOption(string name, bool def)
66 | {
67 | bool p = def;
68 | string[] args = Environment.GetCommandLineArgs();
69 | for (int i = 1; i < args.Length; i++)
70 | {
71 | GetBoolArg(args[i], name, ref p);
72 | }
73 |
74 | return p;
75 | }
76 |
77 | internal static int GetOption(string name, int def)
78 | {
79 | int p = def;
80 | string[] args = Environment.GetCommandLineArgs();
81 | for (int i = 1; i < args.Length; i++)
82 | {
83 | GetIntArg(args[i], name, ref p);
84 | }
85 |
86 | return p;
87 | }
88 |
89 | #endregion
90 |
91 | #region Private Methods
92 |
93 | private static void GetBoolArg(string Arg, string Name, ref bool ArgValue)
94 | {
95 | if (Arg.Length < (Name.Length + 1)) // -name is 1 more than name
96 | return;
97 | if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
98 | return;
99 | if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
100 | ArgValue = true;
101 | }
102 |
103 | private static void GetIntArg(string Arg, string Name, ref int ArgValue)
104 | {
105 | if (Arg.Length < (Name.Length + 3)) // -name:12 is 3 more than name
106 | return;
107 | if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
108 | return;
109 | if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
110 | {
111 | try
112 | {
113 | ArgValue = Convert.ToInt32(Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2));
114 | }
115 | catch
116 | {
117 | }
118 | }
119 | }
120 |
121 | private static bool GetStringArg(string Arg, ref string ArgValue)
122 | {
123 | if (('/' == Arg[0]) || ('-' == Arg[0]))
124 | return false;
125 | ArgValue = Arg;
126 | return true;
127 | }
128 |
129 | private static void GetStringArg(string Arg, string Name, ref string ArgValue)
130 | {
131 | if (Arg.Length < (Name.Length + 3)) // -name:x is 3 more than name
132 | return;
133 | if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
134 | return;
135 | if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
136 | ArgValue = Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2);
137 | }
138 |
139 | private static void ParseArgs()
140 | {
141 | string[] args = Environment.GetCommandLineArgs();
142 | for (int i = 1; i < args.Length; i++)
143 | {
144 | // help
145 | GetBoolArg(args[i], "?", ref Help);
146 | GetBoolArg(args[i], "h", ref Help);
147 | GetBoolArg(args[i], "help", ref Help);
148 | }
149 | }
150 |
151 | #endregion
152 | }
153 | }
154 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlNode.Xpath.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 |
10 | using System;
11 | using System.Xml.XPath;
12 |
13 | namespace HtmlAgilityPack
14 | {
15 | public partial class HtmlNode : IXPathNavigable
16 | {
17 | ///
18 | /// Creates a new XPathNavigator object for navigating this HTML node.
19 | ///
20 | /// An XPathNavigator object. The XPathNavigator is positioned on the node from which the method was called. It is not positioned on the root of the document.
21 | public XPathNavigator CreateNavigator()
22 | {
23 | return new HtmlNodeNavigator(OwnerDocument, this);
24 | }
25 |
26 | ///
27 | /// Creates an XPathNavigator using the root of this document.
28 | ///
29 | ///
30 | public XPathNavigator CreateRootNavigator()
31 | {
32 | return new HtmlNodeNavigator(OwnerDocument, OwnerDocument.DocumentNode);
33 | }
34 |
35 | ///
36 | /// Selects a list of nodes matching the expression.
37 | ///
38 | /// The XPath expression.
39 | /// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
40 | public
41 | #if NET8_0
42 | HtmlNodeCollection?
43 | #else
44 | HtmlNodeCollection
45 | #endif
46 | SelectNodes(string xpath)
47 | {
48 | HtmlNodeCollection list = new HtmlNodeCollection(null);
49 |
50 | HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
51 | XPathNodeIterator it = nav.Select(xpath);
52 | while (it.MoveNext())
53 | {
54 | HtmlNodeNavigator n = (HtmlNodeNavigator) it.Current;
55 | list.Add(n.CurrentNode, false);
56 | }
57 |
58 | if (list.Count == 0 && !OwnerDocument.OptionEmptyCollection)
59 | {
60 | return null;
61 | }
62 |
63 | return list;
64 | }
65 |
66 | ///
67 | /// Selects a list of nodes matching the expression.
68 | ///
69 | /// The XPath expression.
70 | /// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
71 | public
72 | #if NET8_0
73 | HtmlNodeCollection?
74 | #else
75 | HtmlNodeCollection
76 | #endif
77 | SelectNodes(XPathExpression xpath)
78 | {
79 | HtmlNodeCollection list = new HtmlNodeCollection(null);
80 |
81 | HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
82 | XPathNodeIterator it = nav.Select(xpath);
83 | while (it.MoveNext())
84 | {
85 | HtmlNodeNavigator n = (HtmlNodeNavigator) it.Current;
86 | list.Add(n.CurrentNode, false);
87 | }
88 |
89 | if (list.Count == 0 && !OwnerDocument.OptionEmptyCollection)
90 | {
91 | return null;
92 | }
93 |
94 | return list;
95 | }
96 |
97 | ///
98 | /// Selects the first XmlNode that matches the expression.
99 | ///
100 | /// The XPath expression. May not be null.
101 | /// The first that matches the XPath query or a null reference if no matching node was found.
102 | public
103 | #if NET8_0
104 | HtmlNode?
105 | #else
106 | HtmlNode
107 | #endif
108 | SelectSingleNode(string xpath)
109 | {
110 | if (xpath == null)
111 | {
112 | throw new ArgumentNullException("xpath");
113 | }
114 |
115 | HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
116 | XPathNodeIterator it = nav.Select(xpath);
117 | if (!it.MoveNext())
118 | {
119 | return null;
120 | }
121 |
122 | HtmlNodeNavigator node = (HtmlNodeNavigator) it.Current;
123 | return node.CurrentNode;
124 | }
125 |
126 | ///
127 | /// Selects the first XmlNode that matches the expression.
128 | ///
129 | /// The XPath expression.
130 | /// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
131 | public
132 | #if NET8_0
133 | HtmlNode?
134 | #else
135 | HtmlNode
136 | #endif
137 | SelectSingleNode(XPathExpression xpath)
138 | {
139 | if (xpath == null)
140 | {
141 | throw new ArgumentNullException("xpath");
142 | }
143 |
144 | HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
145 | XPathNodeIterator it = nav.Select(xpath);
146 | if (!it.MoveNext())
147 | {
148 | return null;
149 | }
150 |
151 | HtmlNodeNavigator node = (HtmlNodeNavigator)it.Current;
152 | return node.CurrentNode;
153 | }
154 | }
155 | }
156 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/AttributeValueQuoteTests.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Linq;
3 | using System.Net;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Diagnostics;
7 | using System.Globalization;
8 | using System.Threading;
9 | using Xunit;
10 | using System.Xml.Linq;
11 |
12 | namespace HtmlAgilityPack.Tests.NetStandard2_0
13 | {
14 |
15 | public class AttributeValueQuoteTests
16 | {
17 | public static string GlobalHtml1 = "";
18 |
19 | [Fact]
20 | public void GlobalAttributeValueQuote_DoubleQuote()
21 | {
22 | var doc = new HtmlDocument();
23 | doc.GlobalAttributeValueQuote = AttributeValueQuote.DoubleQuote;
24 | doc.LoadHtml(GlobalHtml1);
25 |
26 | Assert.Equal("", doc.DocumentNode.OuterHtml);
27 | }
28 |
29 | [Fact]
30 | public void GlobalAttributeValueQuote_SingleQuote()
31 | {
32 | var doc = new HtmlDocument();
33 | doc.GlobalAttributeValueQuote = AttributeValueQuote.SingleQuote;
34 | doc.LoadHtml(GlobalHtml1);
35 |
36 | Assert.Equal("", doc.DocumentNode.OuterHtml);
37 | }
38 |
39 | [Fact]
40 | public void GlobalAttributeValueQuote_WithoutValue()
41 | {
42 | var doc = new HtmlDocument();
43 | doc.GlobalAttributeValueQuote = AttributeValueQuote.WithoutValue;
44 | doc.LoadHtml(GlobalHtml1);
45 |
46 | Assert.Equal("", doc.DocumentNode.OuterHtml);
47 | }
48 |
49 | [Fact]
50 | public void GlobalAttributeValueQuote_Initial()
51 | {
52 | var doc = new HtmlDocument();
53 | doc.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
54 | doc.LoadHtml(GlobalHtml1);
55 |
56 | Assert.Equal("", doc.DocumentNode.OuterHtml);
57 | }
58 |
59 | [Fact]
60 | public void GlobalAttributeValueQuote_InitialExceptWithoutValue()
61 | {
62 | var doc = new HtmlDocument();
63 | doc.GlobalAttributeValueQuote = AttributeValueQuote.InitialExceptWithoutValue;
64 | doc.LoadHtml(GlobalHtml1);
65 |
66 | Assert.Equal("", doc.DocumentNode.OuterHtml);
67 | }
68 |
69 | [Fact]
70 | public void GlobalAttributeValueQuote_None()
71 | {
72 | var doc = new HtmlDocument();
73 | doc.GlobalAttributeValueQuote = AttributeValueQuote.None;
74 | doc.LoadHtml(GlobalHtml1);
75 |
76 | Assert.Equal("", doc.DocumentNode.OuterHtml);
77 | }
78 |
79 | [Fact]
80 | public void GlobalAttributeValueQuote_DoubleQuote_OutputAsXml()
81 | {
82 | var doc = new HtmlDocument();
83 | doc.GlobalAttributeValueQuote = AttributeValueQuote.DoubleQuote;
84 | doc.OptionOutputAsXml = true;
85 | doc.LoadHtml(GlobalHtml1);
86 |
87 | Assert.Equal("", doc.DocumentNode.OuterHtml);
88 | }
89 |
90 | [Fact]
91 | public void GlobalAttributeValueQuote_SingleQuote_OutputAsXml()
92 | {
93 | var doc = new HtmlDocument();
94 | doc.GlobalAttributeValueQuote = AttributeValueQuote.SingleQuote;
95 | doc.OptionOutputAsXml = true;
96 | doc.LoadHtml(GlobalHtml1);
97 |
98 | Assert.Equal("", doc.DocumentNode.OuterHtml);
99 | }
100 |
101 | [Fact]
102 | public void GlobalAttributeValueQuote_WithoutValue_OutputAsXml()
103 | {
104 | var doc = new HtmlDocument();
105 | doc.GlobalAttributeValueQuote = AttributeValueQuote.WithoutValue;
106 | doc.OptionOutputAsXml = true;
107 | doc.LoadHtml(GlobalHtml1);
108 |
109 | Assert.Equal("", doc.DocumentNode.OuterHtml);
110 | }
111 |
112 | [Fact]
113 | public void GlobalAttributeValueQuote_Initial_OutputAsXml()
114 | {
115 | var doc = new HtmlDocument();
116 | doc.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
117 | doc.OptionOutputAsXml = true;
118 | doc.LoadHtml(GlobalHtml1);
119 |
120 | Assert.Equal("", doc.DocumentNode.OuterHtml);
121 | }
122 |
123 | [Fact]
124 | public void GlobalAttributeValueQuote_InitialExceptWithoutValue_OutputAsXml()
125 | {
126 | var doc = new HtmlDocument();
127 | doc.GlobalAttributeValueQuote = AttributeValueQuote.InitialExceptWithoutValue;
128 | doc.OptionOutputAsXml = true;
129 | doc.LoadHtml(GlobalHtml1);
130 |
131 | Assert.Equal("", doc.DocumentNode.OuterHtml);
132 | }
133 |
134 | [Fact]
135 | public void GlobalAttributeValueQuote_None_OutputAsXml()
136 | {
137 | var doc = new HtmlDocument();
138 | doc.GlobalAttributeValueQuote = AttributeValueQuote.None;
139 | doc.OptionOutputAsXml = true;
140 | doc.LoadHtml(GlobalHtml1);
141 |
142 | Assert.Equal("", doc.DocumentNode.OuterHtml);
143 | }
144 | }
145 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/HtmlWeb.Xpath.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !(NETSTANDARD1_3 || NETSTANDARD1_6) && !METRO
9 | using System;
10 | using System.IO;
11 | using System.Xml;
12 | using System.Xml.Serialization;
13 | using System.Xml.Xsl;
14 |
15 | namespace HtmlAgilityPack
16 | {
17 | public partial class HtmlWeb
18 | {
19 | ///
20 | /// Creates an instance of the given type from the specified Internet resource.
21 | ///
22 | /// The requested URL, such as "http://Myserver/Mypath/Myfile.asp".
23 | /// The URL that specifies the XSLT stylesheet to load.
24 | /// An containing the namespace-qualified arguments used as input to the transform.
25 | /// The requested type.
26 | /// An newly created instance.
27 | public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type)
28 | {
29 | return CreateInstance(htmlUrl, xsltUrl, xsltArgs, type, null);
30 | }
31 |
32 | ///
33 | /// Creates an instance of the given type from the specified Internet resource.
34 | ///
35 | /// The requested URL, such as "http://Myserver/Mypath/Myfile.asp".
36 | /// The URL that specifies the XSLT stylesheet to load.
37 | /// An containing the namespace-qualified arguments used as input to the transform.
38 | /// The requested type.
39 | /// A file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.
40 | /// An newly created instance.
41 | public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type,
42 | string xmlPath)
43 | {
44 | StringWriter sw = new StringWriter();
45 | XmlTextWriter writer = new XmlTextWriter(sw);
46 | if (xsltUrl == null)
47 | {
48 | LoadHtmlAsXml(htmlUrl, writer);
49 | }
50 | else
51 | {
52 | if (xmlPath == null)
53 | {
54 | LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer);
55 | }
56 | else
57 | {
58 | LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer, xmlPath);
59 | }
60 | }
61 |
62 | writer.Flush();
63 | StringReader sr = new StringReader(sw.ToString());
64 | XmlTextReader reader = new XmlTextReader(sr);
65 | XmlSerializer serializer = new XmlSerializer(type);
66 | object o;
67 | try
68 | {
69 | o = serializer.Deserialize(reader);
70 | }
71 | catch (InvalidOperationException ex)
72 | {
73 | throw new Exception(ex + ", --- xml:" + sw);
74 | }
75 |
76 | return o;
77 | }
78 |
79 | ///
80 | /// Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
81 | ///
82 | /// The requested URL, such as "http://Myserver/Mypath/Myfile.asp".
83 | /// The URL that specifies the XSLT stylesheet to load.
84 | /// An XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
85 | /// The XmlTextWriter to which you want to save.
86 | public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer)
87 | {
88 | LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer, null);
89 | }
90 |
91 | ///
92 | /// Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
93 | ///
94 | /// The requested URL, such as "http://Myserver/Mypath/Myfile.asp". May not be null.
95 | /// The URL that specifies the XSLT stylesheet to load.
96 | /// An XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
97 | /// The XmlTextWriter to which you want to save.
98 | /// A file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.
99 | public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer,
100 | string xmlPath)
101 | {
102 | if (htmlUrl == null)
103 | {
104 | throw new ArgumentNullException("htmlUrl");
105 | }
106 |
107 | HtmlDocument doc = Load(htmlUrl);
108 |
109 | if (xmlPath != null)
110 | {
111 | XmlTextWriter w = new XmlTextWriter(xmlPath, doc.Encoding);
112 | doc.Save(w);
113 | w.Close();
114 | }
115 |
116 | if (xsltArgs == null)
117 | {
118 | xsltArgs = new XsltArgumentList();
119 | }
120 |
121 | // add some useful variables to the xslt doc
122 | xsltArgs.AddParam("url", "", htmlUrl);
123 | xsltArgs.AddParam("requestDuration", "", RequestDuration);
124 | xsltArgs.AddParam("fromCache", "", FromCache);
125 |
126 | XslCompiledTransform xslt = new XslCompiledTransform();
127 | xslt.Load(xsltUrl);
128 | xslt.Transform(doc, xsltArgs, writer);
129 | }
130 | }
131 | }
132 | #endif
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/Metro/HtmlWeb.cs:
--------------------------------------------------------------------------------
1 | #if METRO
2 | using System;
3 | using System.IO;
4 | using System.Net;
5 | using System.Net.Http;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace HtmlAgilityPack
10 | {
11 | ///
12 | /// Used for downloading and parsing html from the internet
13 | ///
14 | public class HtmlWeb
15 | {
16 | ///
17 | /// Allows for setting document defaults before loading
18 | ///
19 | public Action PreHandleDocument { get; set; }
20 |
21 | #region Instance Methods
22 |
23 | ///
24 | /// Begins the process of downloading an internet resource
25 | ///
26 | /// Url to the html document
27 | public async Task LoadFromWebAsync(string url)
28 | {
29 | return await LoadFromWebAsync(new Uri(url), null, null);
30 | }
31 |
32 | ///
33 | /// Begins the process of downloading an internet resource
34 | ///
35 | /// Url to the html document
36 | /// The encoding to use while downloading the document
37 | public async Task LoadFromWebAsync(string url, Encoding encoding)
38 | {
39 | return await LoadFromWebAsync(new Uri(url), encoding, null);
40 | }
41 |
42 | ///
43 | /// Begins the process of downloading an internet resource
44 | ///
45 | /// Url to the html document
46 | /// The encoding to use while downloading the document
47 | /// Username to use for credentials in the web request
48 | /// Password to use for credentials in the web request
49 | public async Task LoadFromWebAsync(string url, Encoding encoding, string userName, string password)
50 | {
51 | return await LoadFromWebAsync(new Uri(url), encoding, new NetworkCredential(userName, password));
52 | }
53 |
54 | ///
55 | /// Begins the process of downloading an internet resource
56 | ///
57 | /// Url to the html document
58 | /// The encoding to use while downloading the document
59 | /// Username to use for credentials in the web request
60 | /// Password to use for credentials in the web request
61 | /// Domain to use for credentials in the web request
62 | public async Task LoadFromWebAsync(string url, Encoding encoding, string userName, string password, string domain)
63 | {
64 | return await LoadFromWebAsync(new Uri(url), encoding, new NetworkCredential(userName, password, domain));
65 | }
66 |
67 | ///
68 | /// Begins the process of downloading an internet resource
69 | ///
70 | /// Url to the html document
71 | /// Username to use for credentials in the web request
72 | /// Password to use for credentials in the web request
73 | /// Domain to use for credentials in the web request
74 | public async Task LoadFromWebAsync(string url, string userName, string password, string domain)
75 | {
76 | return await LoadFromWebAsync(new Uri(url), null, new NetworkCredential(userName, password, domain));
77 | }
78 |
79 | ///
80 | /// Begins the process of downloading an internet resource
81 | ///
82 | /// Url to the html document
83 | /// Username to use for credentials in the web request
84 | /// Password to use for credentials in the web request
85 | public async Task LoadFromWebAsync(string url, string userName, string password)
86 | {
87 | return await LoadFromWebAsync(new Uri(url), null, new NetworkCredential(userName, password));
88 | }
89 |
90 | ///
91 | /// Begins the process of downloading an internet resource
92 | ///
93 | /// Url to the html document
94 | /// The credentials to use for authenticating the web request
95 | public async Task LoadFromWebAsync(string url, NetworkCredential credentials)
96 | {
97 | return await LoadFromWebAsync(new Uri(url), null, credentials);
98 | }
99 |
100 | ///
101 | /// Begins the process of downloading an internet resource
102 | ///
103 | /// Url to the html document
104 | /// The encoding to use while downloading the document
105 | /// The credentials to use for authenticating the web request
106 | public async Task LoadFromWebAsync(Uri uri, Encoding encoding, NetworkCredential credentials)
107 | {
108 | var clientHandler = new HttpClientHandler();
109 | if (credentials == null)
110 | clientHandler.UseDefaultCredentials = true;
111 | else
112 | clientHandler.Credentials = credentials;
113 |
114 | var client = new HttpClient(clientHandler);
115 |
116 | var e = await client.GetAsync(uri);
117 | if (e.StatusCode == HttpStatusCode.OK)
118 | {
119 | var html = string.Empty;
120 | if (encoding != null)
121 | {
122 | using (var sr = new StreamReader(await e.Content.ReadAsStreamAsync(), encoding))
123 | {
124 | html = sr.ReadToEnd();
125 | }
126 | }
127 | else
128 | html = await e.Content.ReadAsStringAsync();
129 |
130 | var doc = new HtmlDocument();
131 | if (PreHandleDocument != null)
132 | PreHandleDocument(doc);
133 | doc.LoadHtml(html);
134 | return doc;
135 | }
136 |
137 | throw new Exception("Error downloading html");
138 | }
139 |
140 | #endregion
141 | }
142 | }
143 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlDocument.PreserveOriginalTest.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Xml.XPath;
6 |
7 | namespace HtmlAgilityPack.Tests
8 | {
9 | [TestFixture]
10 | public class HtmlDocumentPreserveOriginalTest
11 | {
12 | private string _contentDirectory;
13 |
14 |
15 |
16 | [OneTimeSetUp]
17 | public void Setup()
18 | {
19 |
20 |
21 | _contentDirectory = Path.GetDirectoryName(typeof(HtmlDocumentTests).Assembly.Location).ToString() + "\\files\\";
22 | // _contentDirectory = Path.Combine(@"C:\Users\Jonathan\Desktop\Z\zzzproject\HtmlAgilityPack\HtmlAgilityPack.Tests\bin\Debug\files\");
23 | }
24 |
25 | [Test]
26 | public void PreserveEmptyAttributesTest()
27 | {
28 | var d = new HtmlDocument();
29 | d.OptionEmptyCollection = true;
30 |
31 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
32 |
33 | d.OptionDefaultUseOriginalName = true;
34 | //d.OptionPreserveEmptyAttributes = true;
35 |
36 | var html = @"
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
47 |
48 |
50 |
51 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | ";
65 | d.LoadHtml(html);
66 |
67 | var outer = d.DocumentNode.OuterHtml;
68 |
69 | var xpath = XPathExpression.Compile("/form/page/page-header/page-header-actions/button[@enterEditButton]");
70 | var nodes = d.DocumentNode.SelectNodes(xpath);
71 |
72 | Assert.AreEqual(nodes?.Count, 1, "xpath expression should return 1 node");
73 | Assert.AreEqual(d.DocumentNode.OuterHtml, html);
74 | }
75 |
76 | [Test]
77 | public void PreserveOriginalCasingTest()
78 | {
79 | var d = new HtmlDocument();
80 | d.OptionEmptyCollection = true;
81 |
82 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
83 |
84 | d.OptionDefaultUseOriginalName = true;
85 | //d.OptionPreserveEmptyAttributes = true;
86 |
87 | var html = @"
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
98 |
99 |
101 |
102 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | ";
116 | d.LoadHtml(html);
117 |
118 | var xpath = XPathExpression.Compile("/form/page/page-Header/page-Header-Actions/button[@enterEditButton]");
119 | var nodes = d.DocumentNode.SelectNodes(xpath);
120 |
121 | Assert.AreEqual(nodes?.Count, 1, "xpath expression should return 1 node");
122 | Assert.AreEqual(d.DocumentNode.OuterHtml, html);
123 | }
124 |
125 |
126 | [Test]
127 | public void PreserveOriginalQuoteTest()
128 | {
129 | var d = new HtmlDocument();
130 | d.OptionEmptyCollection = true;
131 |
132 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
133 | d.OptionDefaultUseOriginalName = true;
134 |
135 | var filePath = Path.Combine(_contentDirectory, "attr_quote.html");
136 | var filePathExpected = Path.Combine(_contentDirectory, "attr_quote_expected.html");
137 | d.Load(filePath);
138 |
139 | var xpath = XPathExpression.Compile("/form/page/page-body/card/data-group/mat-form-field[@*[local-name() = 'xdt:Transform' and . = \"InsertAfter(mat-form-field[mat-select/@name = 'tipoProdutoId'])\"]]/mat-select/mat-option");
140 | var nodes = d.DocumentNode.SelectNodes(xpath);
141 |
142 | Assert.AreEqual(nodes?.Count, 1, "xpath expression should return 1 node");
143 | Assert.AreEqual(File.ReadAllText(filePathExpected), d.DocumentNode.OuterHtml);
144 |
145 | var clone = nodes[0].CloneNode(true);
146 |
147 | var expectedOuterNode = @"
148 |
149 |
150 | {{ dimension.code }} - {{ dimension.description }}
151 | ";
152 |
153 | Assert.AreEqual(expectedOuterNode, clone.OuterHtml);
154 |
155 | }
156 |
157 |
158 | [Test]
159 | public void PreserveClonedEmptyAttributesTest()
160 | {
161 | var d = new HtmlDocument();
162 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
163 | d.OptionDefaultUseOriginalName = true;
164 |
165 | var html = @"";
166 | d.LoadHtml(html);
167 |
168 | var cloned = d.DocumentNode.CloneNode(true);
169 |
170 | Assert.AreEqual(@"", cloned.OuterHtml);
171 | }
172 |
173 | [Test]
174 | public void PreserveQuoteTypeForLoadedAttributes()
175 | {
176 | var input = HtmlNode.CreateNode("");
177 | var checkedAttribute = input.Attributes.First();
178 |
179 | // Result is: Value: '' (empty string)
180 | Assert.AreEqual("", checkedAttribute.Value);
181 |
182 | // Result is: QuoteType: WithoutValue
183 | Assert.AreEqual(AttributeValueQuote.WithoutValue, checkedAttribute.QuoteType);
184 | }
185 | }
186 | }
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlAgilityPack.Tests.Net45.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 | {F7D2CBBC-E23E-478E-865B-6BE445B55EC8}
10 | Library
11 | Properties
12 | HtmlAgilityPack.Tests.fx._4._5
13 | HtmlAgilityPack.Tests.fx.4.5
14 | v4.5
15 | 512
16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 | 15.0
18 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
19 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
20 | False
21 | UnitTest
22 |
23 |
24 |
25 |
26 |
27 | true
28 | full
29 | false
30 | bin\Debug\
31 | DEBUG;TRACE
32 | prompt
33 | 4
34 |
35 |
36 | pdbonly
37 | true
38 | bin\Release\
39 | TRACE
40 | prompt
41 | 4
42 |
43 |
44 |
45 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
46 |
47 |
48 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
49 |
50 |
51 | ..\..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | Designer
69 |
70 |
71 |
72 |
73 | Always
74 |
75 |
76 | Always
77 |
78 |
79 | PreserveNewest
80 |
81 |
82 | Always
83 |
84 |
85 | PreserveNewest
86 |
87 |
88 | PreserveNewest
89 |
90 |
91 | PreserveNewest
92 |
93 |
94 |
95 |
96 | {8dcfde1c-263f-41d4-b518-9b7ee06f7d52}
97 | HtmlAgilityPack.Net45
98 |
99 |
100 |
101 |
102 |
103 |
104 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/crc32.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | using System;
9 |
10 | namespace HtmlAgilityPack
11 | {
12 | ///
13 | /// A utility class to compute CRC32.
14 | ///
15 | [System.Obsolete("This type should not be used; it is intended for internal use in HTML Agility Pack.")]
16 | #if !(NETSTANDARD1_3 || NETSTANDARD1_6) || WINDOWS_UWP
17 | [CLSCompliant(false)]
18 | #endif
19 | public class Crc32
20 | {
21 | #region Fields
22 |
23 | private uint _crc32;
24 |
25 | #endregion
26 |
27 | #region Static Members
28 |
29 | private static uint[] crc_32_tab = // CRC polynomial 0xedb88320
30 | {
31 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
32 | 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
33 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
34 | 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
35 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
36 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
37 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
38 | 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
39 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
40 | 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
41 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
42 | 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
43 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
44 | 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
45 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
46 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
47 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
48 | 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
49 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
50 | 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
51 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
52 | 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
53 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
54 | 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
55 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
56 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
57 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
58 | 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
59 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
60 | 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
61 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
62 | 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
63 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
64 | 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
65 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
66 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
67 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
68 | 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
69 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
70 | 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
71 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
72 | 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
73 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
74 | };
75 |
76 | #endregion
77 |
78 | #region Properties
79 |
80 | internal uint CheckSum
81 | {
82 | get { return _crc32; }
83 | set { _crc32 = value; }
84 | }
85 |
86 | #endregion
87 |
88 | #region Public Methods
89 |
90 | ///
91 | /// Compute a checksum for a given array of bytes.
92 | ///
93 | /// The array of bytes to compute the checksum for.
94 | /// The computed checksum.
95 | public static uint CRC32Bytes(byte[] bytes)
96 | {
97 | uint oldcrc32;
98 | oldcrc32 = 0xFFFFFFFF;
99 | int len = bytes.Length;
100 |
101 | for (int i = 0; len > 0; i++)
102 | {
103 | --len;
104 | oldcrc32 = UPDC32(bytes[len], oldcrc32);
105 | }
106 |
107 | return ~oldcrc32;
108 | }
109 |
110 | ///
111 | /// Compute a checksum for a given string.
112 | ///
113 | /// The string to compute the checksum for.
114 | /// The computed checksum.
115 | public static uint CRC32String(string text)
116 | {
117 | uint oldcrc32;
118 | oldcrc32 = 0xFFFFFFFF;
119 | int len = text.Length;
120 | ushort uCharVal;
121 | byte lowByte, hiByte;
122 |
123 | for (int i = 0; len > 0; i++)
124 | {
125 | --len;
126 | uCharVal = text[len];
127 | unchecked
128 | {
129 | lowByte = (byte) (uCharVal & 0x00ff);
130 | hiByte = (byte) (uCharVal >> 8);
131 | }
132 |
133 | oldcrc32 = UPDC32(hiByte, oldcrc32);
134 | oldcrc32 = UPDC32(lowByte, oldcrc32);
135 | }
136 |
137 | return ~oldcrc32;
138 | }
139 |
140 | #endregion
141 |
142 | #region Internal Methods
143 |
144 | internal uint AddToCRC32(int c)
145 | {
146 | return AddToCRC32((ushort) c);
147 | }
148 |
149 | internal uint AddToCRC32(ushort c)
150 | {
151 | byte lowByte, hiByte;
152 | lowByte = (byte) (c & 0x00ff);
153 | hiByte = (byte) (c >> 8);
154 | _crc32 = UPDC32(hiByte, _crc32);
155 | _crc32 = UPDC32(lowByte, _crc32);
156 | return ~_crc32;
157 | }
158 |
159 | #endregion
160 |
161 | #region Private Methods
162 |
163 | private static uint UPDC32(byte octet, uint crc)
164 | {
165 | return (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8));
166 | }
167 |
168 | #endregion
169 | }
170 | }
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.UAP10/HtmlAgilityPack.UAP10.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EEA39F83-F080-4FB0-9471-E103517D0A1C}
8 | Library
9 | Properties
10 | HtmlAgilityPack
11 | HtmlAgilityPack
12 | en-US
13 | UAP
14 | 10.0.17134.0
15 | 10.0.10586.0
16 | 14
17 | 512
18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | AnyCPU
30 | true
31 | full
32 | false
33 | bin\Debug\
34 | TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
35 | prompt
36 | 4
37 |
38 |
39 | AnyCPU
40 | pdbonly
41 | true
42 | bin\Release\
43 | TRACE;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
44 | prompt
45 | 4
46 | bin\Release\HtmlAgilityPack.XML
47 |
48 |
49 | x86
50 | true
51 | bin\x86\Debug\
52 | TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
53 | ;2008
54 | full
55 | AnyCPU
56 | false
57 | prompt
58 | bin\x86\Debug\HtmlAgilityPack.XML
59 |
60 |
61 | x86
62 | bin\x86\Release\
63 | TRACE;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
64 | true
65 | ;2008
66 | pdbonly
67 | AnyCPU
68 | false
69 | prompt
70 | bin\x86\Release\HtmlAgilityPack.XML
71 |
72 |
73 | ARM
74 | true
75 | bin\ARM\Debug\
76 | TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
77 | ;2008
78 | full
79 | ARM
80 | false
81 | prompt
82 |
83 |
84 | ARM
85 | bin\ARM\Release\
86 | TRACE;NETFX_CORE;WINDOWS_UWP
87 | true
88 | ;2008
89 | pdbonly
90 | ARM
91 | false
92 | prompt
93 |
94 |
95 | x64
96 | true
97 | bin\x64\Debug\
98 | TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;NETSTANDARD;NETSTANDARD1_3
99 | ;2008
100 | full
101 | x64
102 | false
103 | prompt
104 |
105 |
106 | x64
107 | bin\x64\Release\
108 | TRACE;NETFX_CORE;WINDOWS_UWP
109 | true
110 | ;2008
111 | pdbonly
112 | x64
113 | false
114 | prompt
115 |
116 |
117 | PackageReference
118 |
119 |
120 | true
121 |
122 |
123 | HtmlAgilityPack.snk
124 |
125 |
126 |
127 |
128 |
129 |
130 | 5.2.4
131 |
132 |
133 | 4.3.4
134 |
135 |
136 | 4.3.0
137 |
138 |
139 | 4.3.0
140 |
141 |
142 | 4.3.0
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | 14.0
151 |
152 |
153 |
154 |
155 |
156 |
157 |
164 |
--------------------------------------------------------------------------------
/src/HtmlAgilityPack.Shared/MixedCodeDocumentFragmentList.cs:
--------------------------------------------------------------------------------
1 | // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
2 | // Website & Documentation: https://html-agility-pack.net
3 | // Forum & Issues: https://github.com/zzzprojects/html-agility-pack
4 | // License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
5 | // More projects: https://zzzprojects.com/
6 | // Copyright © ZZZ Projects Inc. All rights reserved.
7 |
8 | #if !METRO
9 |
10 | using System;
11 | using System.Collections;
12 | using System.Collections.Generic;
13 |
14 | namespace HtmlAgilityPack
15 | {
16 | ///
17 | /// Represents a list of mixed code fragments.
18 | ///
19 | public class MixedCodeDocumentFragmentList : IEnumerable
20 | {
21 | #region Fields
22 |
23 | private MixedCodeDocument _doc;
24 | private List _items = new List();
25 |
26 | #endregion
27 |
28 | #region Constructors
29 |
30 | internal MixedCodeDocumentFragmentList(MixedCodeDocument doc)
31 | {
32 | _doc = doc;
33 | }
34 |
35 | #endregion
36 |
37 | #region Properties
38 |
39 | ///
40 | /// Gets the Document
41 | ///
42 | public MixedCodeDocument Doc
43 | {
44 | get { return _doc; }
45 | }
46 |
47 | ///
48 | /// Gets the number of fragments contained in the list.
49 | ///
50 | public int Count
51 | {
52 | get { return _items.Count; }
53 | }
54 |
55 | ///
56 | /// Gets a fragment from the list using its index.
57 | ///
58 | public MixedCodeDocumentFragment this[int index]
59 | {
60 | get { return _items[index]; }
61 | }
62 |
63 | #endregion
64 |
65 | #region IEnumerable Members
66 |
67 | ///
68 | /// Gets an enumerator that can iterate through the fragment list.
69 | ///
70 | IEnumerator IEnumerable.GetEnumerator()
71 | {
72 | return GetEnumerator();
73 | }
74 |
75 | #endregion
76 |
77 | #region Public Methods
78 |
79 | ///
80 | /// Appends a fragment to the list of fragments.
81 | ///
82 | /// The fragment to append. May not be null.
83 | public void Append(MixedCodeDocumentFragment newFragment)
84 | {
85 | if (newFragment == null)
86 | {
87 | throw new ArgumentNullException("newFragment");
88 | }
89 |
90 | _items.Add(newFragment);
91 | }
92 |
93 | ///
94 | /// Gets an enumerator that can iterate through the fragment list.
95 | ///
96 | public MixedCodeDocumentFragmentEnumerator GetEnumerator()
97 | {
98 | return new MixedCodeDocumentFragmentEnumerator(_items);
99 | }
100 |
101 | ///
102 | /// Prepends a fragment to the list of fragments.
103 | ///
104 | /// The fragment to append. May not be null.
105 | public void Prepend(MixedCodeDocumentFragment newFragment)
106 | {
107 | if (newFragment == null)
108 | {
109 | throw new ArgumentNullException("newFragment");
110 | }
111 |
112 | _items.Insert(0, newFragment);
113 | }
114 |
115 | ///
116 | /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.
117 | ///
118 | /// The fragment to remove. May not be null.
119 | public void Remove(MixedCodeDocumentFragment fragment)
120 | {
121 | if (fragment == null)
122 | {
123 | throw new ArgumentNullException("fragment");
124 | }
125 |
126 | int index = GetFragmentIndex(fragment);
127 | if (index == -1)
128 | {
129 | throw new IndexOutOfRangeException();
130 | }
131 |
132 | RemoveAt(index);
133 | }
134 |
135 | ///
136 | /// Remove all fragments from the list.
137 | ///
138 | public void RemoveAll()
139 | {
140 | _items.Clear();
141 | }
142 |
143 | ///
144 | /// Remove a fragment from the list of fragments, using its index in the list.
145 | ///
146 | /// The index of the fragment to remove.
147 | public void RemoveAt(int index)
148 | {
149 | //MixedCodeDocumentFragment frag = (MixedCodeDocumentFragment) _items[index];
150 | _items.RemoveAt(index);
151 | }
152 |
153 | #endregion
154 |
155 | #region Internal Methods
156 |
157 | internal void Clear()
158 | {
159 | _items.Clear();
160 | }
161 |
162 | internal int GetFragmentIndex(MixedCodeDocumentFragment fragment)
163 | {
164 | if (fragment == null)
165 | {
166 | throw new ArgumentNullException("fragment");
167 | }
168 |
169 | for (int i = 0; i < _items.Count; i++)
170 | {
171 | if ((_items[i]) == fragment)
172 | {
173 | return i;
174 | }
175 | }
176 |
177 | return -1;
178 | }
179 |
180 | #endregion
181 |
182 | #region Nested type: MixedCodeDocumentFragmentEnumerator
183 |
184 | ///
185 | /// Represents a fragment enumerator.
186 | ///
187 | public class MixedCodeDocumentFragmentEnumerator : IEnumerator
188 | {
189 | #region Fields
190 |
191 | private int _index;
192 | private IList _items;
193 |
194 | #endregion
195 |
196 | #region Constructors
197 |
198 | internal MixedCodeDocumentFragmentEnumerator(IList items)
199 | {
200 | _items = items;
201 | _index = -1;
202 | }
203 |
204 | #endregion
205 |
206 | #region Properties
207 |
208 | ///
209 | /// Gets the current element in the collection.
210 | ///
211 | public MixedCodeDocumentFragment Current
212 | {
213 | get { return (MixedCodeDocumentFragment) (_items[_index]); }
214 | }
215 |
216 | #endregion
217 |
218 | #region IEnumerator Members
219 |
220 | ///
221 | /// Gets the current element in the collection.
222 | ///
223 | object IEnumerator.Current
224 | {
225 | get { return (Current); }
226 | }
227 |
228 | ///
229 | /// Advances the enumerator to the next element of the collection.
230 | ///
231 | /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
232 | public bool MoveNext()
233 | {
234 | _index++;
235 | return (_index < _items.Count);
236 | }
237 |
238 | ///
239 | /// Sets the enumerator to its initial position, which is before the first element in the collection.
240 | ///
241 | public void Reset()
242 | {
243 | _index = -1;
244 | }
245 |
246 | #endregion
247 | }
248 |
249 | #endregion
250 | }
251 | }
252 | #endif
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlNode.Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using NUnit.Framework;
6 | using Assert = NUnit.Framework.Assert;
7 |
8 | namespace HtmlAgilityPack.Tests
9 | {
10 | [TestFixture]
11 | public class HtmlNode2
12 | {
13 | //[Test(Description =
14 | // "Attributes should maintain their original character casing if OptionOutputOriginalCase is true")]
15 | //public void EnsureAttributeOriginalCaseIsPreserved()
16 | //{
17 | // var html = "";
18 | // var doc = new HtmlDocument
19 | // {
20 | // OptionOutputOriginalCase = true
21 | // };
22 | // doc.LoadHtml(html);
23 | // var div = doc.DocumentNode.Descendants("div").FirstOrDefault();
24 | // var writer = new StringWriter();
25 | // div.WriteAttributes(writer, false);
26 | // var result = writer.GetStringBuilder().ToString();
27 | // Assert.AreEqual(" AttributeIsThis=\"val\"", result);
28 | //}
29 |
30 | [Test]
31 | public void ScriptingText()
32 | {
33 | var html = @"
34 |
35 |
36 | SEE title
37 |
38 |
39 |
40 |
41 |
42 | 222
43 |
44 |
45 | ";
46 |
47 | {
48 | HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
49 | htmlDocument.LoadHtml(html);
50 |
51 | var content1 = htmlDocument.DocumentNode.SelectSingleNode("//head").InnerText;
52 | var content2 = htmlDocument.DocumentNode.SelectSingleNode("//script").InnerText;
53 | var content3 = htmlDocument.DocumentNode.SelectSingleNode("//style").InnerText;
54 | var content4 = htmlDocument.DocumentNode.SelectSingleNode("//body").InnerText;
55 | var content5 = htmlDocument.DocumentNode.SelectSingleNode("//html").InnerText;
56 | var content6 = htmlDocument.DocumentNode.SelectSingleNode("//body/script").InnerText;
57 |
58 | Assert.AreEqual("\r\n SEE title\r\n\tSEE script \r\n\tSEE style\r\n", content1);
59 | Assert.AreEqual("SEE script ", content2);
60 | Assert.AreEqual("SEE style", content3);
61 | Assert.AreEqual("\r\n\r\n222\r\n\r\n", content4);
62 | Assert.AreEqual("\r\n\r\n SEE title\r\n\t\r\n\t\r\n\r\n\r\n\r\n222\r\n\r\n\r\n", content5);
63 | Assert.AreEqual("NOTSEE script", content6);
64 | }
65 |
66 | {
67 | HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
68 | htmlDocument.BackwardCompatibility = false;
69 | htmlDocument.LoadHtml(html);
70 |
71 | var content1 = htmlDocument.DocumentNode.SelectSingleNode("//head").InnerText;
72 | var content2 = htmlDocument.DocumentNode.SelectSingleNode("//script").InnerText;
73 | var content3 = htmlDocument.DocumentNode.SelectSingleNode("//style").InnerText;
74 | var content4 = htmlDocument.DocumentNode.SelectSingleNode("//body").InnerText;
75 | var content5 = htmlDocument.DocumentNode.SelectSingleNode("//html").InnerText;
76 | var content6 = htmlDocument.DocumentNode.SelectSingleNode("//body/script").InnerText;
77 |
78 | Assert.AreEqual(" SEE titleSEE script SEE style", content1);
79 | Assert.AreEqual("SEE script ", content2);
80 | Assert.AreEqual("SEE style", content3);
81 | Assert.AreEqual("222", content4);
82 | Assert.AreEqual(" SEE title222", content5);
83 | Assert.AreEqual("NOTSEE script", content6);
84 | }
85 | }
86 |
87 | [Test]
88 | public void ReadNotCloseTag()
89 | {
90 | var document = new HtmlDocument();
91 | document.LoadHtml("");
92 | var span = document.DocumentNode.SelectSingleNode("//span");
93 | if (span == null) throw new Exception("Failed to find span element");
94 | var OuterHtml = span.OuterHtml;
95 | var InnerHtml = span.InnerHtml;
96 | var InnerText = span.InnerText;
97 |
98 | Assert.IsNotNull(OuterHtml);
99 | Assert.IsNotNull(InnerHtml);
100 | Assert.IsNotNull(InnerText);
101 | }
102 |
103 |
104 | [Test]
105 | public void checkAttributForTextComment()
106 | {
107 | var doc = new HtmlAgilityPack.HtmlDocument();
108 | doc.LoadHtml(@" some text
");
109 | var div = doc.GetElementbyId("foo");
110 | int count = 0;
111 | Exception exception = null;
112 | foreach (var textNode in div.ChildNodes)
113 | {
114 | try
115 | {
116 | textNode.Id = "1";
117 | count++;
118 | }
119 | catch (Exception e)
120 | {
121 | exception = e;
122 |
123 | }
124 | }
125 |
126 | Assert.AreEqual(count, 1);
127 | Assert.IsNotNull(exception);
128 | }
129 |
130 |
131 | [Test]
132 | public void Prepend_CheckOrder()
133 | {
134 | HtmlNode source = HtmlNode.CreateNode(@"
135 |
136 | - Alpha
137 | - Bravo
138 | - Charlie
139 |
140 | ");
141 | HtmlNode destination = HtmlNode.CreateNode(@"
142 |
143 | - Delta
144 | - Echo
145 | - Foxtrot
146 |
147 | ");
148 |
149 | destination.PrependChildren(source.ChildNodes);
150 |
151 | Assert.AreEqual(destination.WriteTo()
152 | , @"
153 | - Alpha
154 | - Bravo
155 | - Charlie
156 |
157 | - Delta
158 | - Echo
159 | - Foxtrot
160 |
");
161 | }
162 |
163 | [Test]
164 | public void OptionMaxNestedChildNodes_NotSet_IsNotEnforced()
165 | {
166 | var html = "";
167 | var doc = new HtmlDocument();
168 |
169 | doc.LoadHtml(html);
170 |
171 | Assert.IsNotNull(doc);
172 | Assert.AreEqual(html, doc.Text);
173 | }
174 |
175 | [Test]
176 | public void OptionMaxNestedChildNodes_SetToZero_IsNotEnforced()
177 | {
178 | var html = "";
179 | var doc = new HtmlDocument();
180 | doc.OptionMaxNestedChildNodes = 0;
181 |
182 | doc.LoadHtml(html);
183 |
184 | Assert.IsNotNull(doc);
185 | Assert.AreEqual(html, doc.Text);
186 | }
187 |
188 | [Test]
189 | public void OptionMaxNestedChildNodes_WithinMax_NoException()
190 | {
191 | var html = "";
192 | var doc = new HtmlDocument();
193 | doc.OptionMaxNestedChildNodes = 8;
194 |
195 | doc.LoadHtml(html);
196 | }
197 |
198 | [Test]
199 | [ExpectedException(typeof(ApplicationException))]
200 | public void OptionMaxNestedChildNodes_AbotMax()
201 | {
202 | var html = "";
203 | var doc = new HtmlDocument();
204 | doc.OptionMaxNestedChildNodes = 7;
205 | string message = "";
206 | try
207 | {
208 | doc.LoadHtml(html);
209 | }
210 | catch (Exception e)
211 | {
212 | message = e.Message;
213 | }
214 |
215 | Assert.AreEqual("Document has more than 7 nested tags. This is likely due to the page not closing tags properly.", message);
216 | }
217 | }
218 | }
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlDocument.PreserveOriginalTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Xml.XPath;
5 | using Xunit;
6 |
7 | namespace HtmlAgilityPack.Tests.NetStandard2_0
8 | {
9 | public class HtmlDocumentPreserveOriginalTest
10 | {
11 | [Fact]
12 | public void PreserveEmptyAttributesTest()
13 | {
14 | var d = new HtmlDocument();
15 | d.OptionEmptyCollection = true;
16 |
17 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
18 |
19 | d.OptionDefaultUseOriginalName = true;
20 | //d.OptionPreserveEmptyAttributes = true;
21 |
22 | var html = @"
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | ";
51 | d.LoadHtml(html);
52 |
53 | var outer = d.DocumentNode.OuterHtml;
54 |
55 | var xpath = XPathExpression.Compile("/form/page/page-header/page-header-actions/button[@enterEditButton]");
56 | var nodes = d.DocumentNode.SelectNodes(xpath);
57 |
58 | Assert.Equal(1, nodes?.Count);
59 | Assert.Equal(html, d.DocumentNode.OuterHtml);
60 | }
61 |
62 | [Fact]
63 | public void PreserveOriginalCasingTest()
64 | {
65 | var d = new HtmlDocument();
66 | d.OptionEmptyCollection = true;
67 |
68 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
69 |
70 | d.OptionDefaultUseOriginalName = true;
71 | //d.OptionPreserveEmptyAttributes = true;
72 |
73 | var html = @"
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
84 |
85 |
87 |
88 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | ";
102 | d.LoadHtml(html);
103 |
104 | var xpath = XPathExpression.Compile("/form/page/page-Header/page-Header-Actions/button[@enterEditButton]");
105 | var nodes = d.DocumentNode.SelectNodes(xpath);
106 |
107 | Assert.Equal(1, nodes?.Count);
108 | Assert.Equal(html, d.DocumentNode.OuterHtml);
109 | }
110 |
111 |
112 | [Fact]
113 | public void PreserveOriginalQuoteTest()
114 | {
115 | var contentDirectory = Path.GetDirectoryName(typeof(HtmlDocumentPreserveOriginalTest).Assembly.Location).ToString() + "\\files\\";
116 |
117 | var d = new HtmlDocument();
118 | d.OptionEmptyCollection = true;
119 |
120 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
121 | d.OptionDefaultUseOriginalName = true;
122 |
123 | var filePath = Path.Combine(contentDirectory, "attr_quote.html");
124 | var filePathExpected = Path.Combine(contentDirectory, "attr_quote_expected.html");
125 | d.Load(filePath);
126 |
127 | var xpath = XPathExpression.Compile("/form/page/page-body/card/data-group/mat-form-field[@*[local-name() = 'xdt:Transform' and . = \"InsertAfter(mat-form-field[mat-select/@name = 'tipoProdutoId'])\"]]/mat-select/mat-option");
128 | var nodes = d.DocumentNode.SelectNodes(xpath);
129 |
130 | Assert.Equal(1, nodes?.Count);
131 |
132 | nodes[0].ParentNode.Attributes["required"].Value = "true";
133 |
134 | Assert.Equal(File.ReadAllText(filePathExpected), d.DocumentNode.OuterHtml);
135 |
136 | var clone = nodes[0].CloneNode(true);
137 |
138 | var expectedOuterNode = @"
139 |
140 |
141 | {{ dimension.code }} - {{ dimension.description }}
142 | ";
143 |
144 | Assert.Equal(expectedOuterNode, clone.OuterHtml);
145 |
146 | }
147 |
148 |
149 | [Fact]
150 | public void PreserveClonedEmptyAttributesTest()
151 | {
152 | var d = new HtmlDocument();
153 | d.GlobalAttributeValueQuote = AttributeValueQuote.Initial;
154 | d.OptionDefaultUseOriginalName = true;
155 |
156 | var html = @"";
157 | d.LoadHtml(html);
158 |
159 | var cloned = d.DocumentNode.CloneNode(true);
160 |
161 | Assert.Equal(@"", cloned.OuterHtml);
162 | }
163 |
164 | [Fact]
165 | public void PreserveEmptyAttributesWithInitialTest()
166 | {
167 | var d = new HtmlDocument { GlobalAttributeValueQuote = AttributeValueQuote.InitialExceptWithoutValue };
168 | d.LoadHtml("");
169 |
170 | var node = d.DocumentNode.SelectSingleNode("//bar");
171 | var outer = node.OuterHtml;
172 |
173 | Assert.Equal("", outer);
174 | }
175 |
176 | [Fact]
177 | public void PreserveEmptyAttributes()
178 | {
179 | var d = new HtmlDocument { GlobalAttributeValueQuote = AttributeValueQuote.InitialExceptWithoutValue };
180 | d.LoadHtml("Nothing to show");
181 |
182 | var node = d.DocumentNode.SelectSingleNode("//li");
183 | var outer = node.OuterHtml;
184 |
185 | Assert.Equal($"Nothing to show", outer);
186 | }
187 |
188 | [Fact]
189 | public void PreserveQuoteTypeForLoadedAttributes()
190 | {
191 | var input = HtmlNode.CreateNode("");
192 | var checkedAttribute = input.Attributes.First();
193 |
194 | // Result is: Value: '' (empty string)
195 | Assert.Equal("", checkedAttribute.Value);
196 |
197 | // Result is: QuoteType: WithoutValue
198 | Assert.Equal(AttributeValueQuote.WithoutValue, checkedAttribute.QuoteType);
199 | }
200 | [Fact]
201 | public void PreserveQuoteTypeForLoadedAttributes2()
202 | {
203 | var d = new HtmlDocument { GlobalAttributeValueQuote = AttributeValueQuote.InitialExceptWithoutValue };
204 | d.LoadHtml(@"");
205 |
206 | var node = d.DocumentNode.SelectSingleNode("//bar");
207 | var outer = node.OuterHtml;
208 |
209 | Assert.Equal($"", outer);
210 | }
211 | }
212 | }
--------------------------------------------------------------------------------
/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/EncapsulatorTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Reflection.Metadata;
6 | using Xunit;
7 |
8 | namespace HtmlAgilityPack.Tests.NetStandard2_0
9 | {
10 | public class EncapsulatorTests
11 | {
12 | //[Fact]
13 | //public void StackOverFlow_Test()
14 | //{
15 | // HtmlWeb stackoverflowSite = new HtmlWeb();
16 | // HtmlDocument htmlDocument = stackoverflowSite.Load("https://stackoverflow.com/questions");
17 |
18 | // StackOverflowPage stackOverflowPage = htmlDocument.DocumentNode.GetEncapsulatedData();
19 |
20 | // Assert.NotNull(stackOverflowPage);
21 | //}
22 |
23 | //[Fact]
24 | //public void Dictionary_Test()
25 | //{
26 | // HtmlWeb wortSite = new HtmlWeb();
27 | // HtmlDocument htmlDocument = wortSite.Load("https://wort.ir/woerterbuch/deutsch-persisch/Buch");
28 |
29 | // Word wort = htmlDocument.DocumentNode.GetEncapsulatedData();
30 |
31 | // Assert.NotNull(wort);
32 | //}
33 |
34 | [Fact]
35 | public void EncapsulatedOuterHtml_Test()
36 | {
37 | var html = @"
38 |
39 |
3
40 |
44 |
world
45 |
46 | ";
47 | var document = new HtmlDocument();
48 | document.LoadHtml(html);
49 | var outerHtml = document.DocumentNode.GetEncapsulatedData();
50 | Assert.True(outerHtml.Item3.Href == "3.html");
51 | Assert.True(outerHtml.Item3.Name == "3");
52 |
53 | Assert.True(outerHtml.Items.Count == 3);
54 | Assert.True(outerHtml.Items.All(o => o.Href != null));
55 | }
56 |
57 | [Fact]
58 | public void Encapsulation_Test2()
59 | {
60 | var docoument = new HtmlDocument();
61 | docoument.LoadHtml(EncapsulationTestHtml.Html);
62 | var testHtml = docoument.DocumentNode.GetEncapsulatedData();
63 |
64 | Assert.True(testHtml.Title == "Test");
65 | Assert.True(testHtml.H1 == "Test");
66 | Assert.NotEmpty(testHtml.Link1);
67 | Assert.NotEmpty(testHtml.Link2);
68 | Assert.NotNull(testHtml.Link3);
69 |
70 | Assert.NotNull(testHtml.Form);
71 |
72 | Assert.True(testHtml.Articles.Count == 2);
73 | Assert.True(testHtml.Articles.All(o => o.Id != null));
74 | }
75 | }
76 |
77 |
78 | #region StackOverFlow_TestClasses
79 |
80 | [HasXPath]
81 | public class StackOverflowPage
82 | {
83 |
84 | [XPath("//*[@id='questions']/div")]
85 | public IEnumerable Questions { get; set; }
86 |
87 |
88 |
89 | [XPath("//*[@id='hot-network-questions']/ul//li")]
90 | public IEnumerable GetHotNetworkQuestions { get; set; }
91 |
92 | }
93 |
94 | [HasXPath]
95 | [DebuggerDisplay("StackOverflowQuestion : {Question.QuestionTitle}")]
96 | public class StackOverflowQuestion
97 | {
98 |
99 | [XPath("/div[@class='statscontainer']")]
100 | public StatisticsBox Statistics { get; set; }
101 |
102 |
103 | [XPath("/div[@class='summary']")]
104 | public QuestionBox Question { get; set; }
105 |
106 | // The XPath below is an alternativ XPath if the uncommented one does not work
107 | // [XPath("/div[@class='summary']/div[3]/div")]
108 | [XPath("/div[@class='summary']/div[@class='started fr']/div")]
109 | public UserBox User { get; set; }
110 | }
111 |
112 |
113 |
114 | [HasXPath]
115 | [DebuggerDisplay("Votes={Votes} , Answers={Answers} , Views={Views}")]
116 | public class StatisticsBox
117 | {
118 | [XPath("/div[1]/div[1]/div/span/strong")]
119 | public int Votes { get; set; }
120 |
121 | [XPath("/div[1]/div[2]/strong")]
122 | public int Answers { get; set; }
123 |
124 | [XPath("/div[2]")]
125 | public string Views { get; set; }
126 |
127 |
128 | }
129 |
130 |
131 |
132 |
133 |
134 | [HasXPath]
135 | [DebuggerDisplay("QuestionTitle={QuestionTitle}")]
136 | public class QuestionBox
137 | {
138 | [XPath("/h3/a")]
139 | public string QuestionTitle { get; set; }
140 |
141 | [XPath("/h3/a", "href")]
142 | public string QuestionLink { get; set; }
143 |
144 | [XPath("/div[starts-with(@class,'tags')]//a")]
145 | public IEnumerable Tags { get; set; }
146 | }
147 |
148 |
149 |
150 | [HasXPath]
151 | [DebuggerDisplay("UserID={UserID} , ReputationScore={ReputationScore}")]
152 | public class UserBox
153 | {
154 | [XPath("/div[@class='user-action-time']/span", "title")]
155 | public DateTime ExactTime { get; set; }
156 |
157 | [XPath("/div[@class='user-action-time']/span")]
158 | public string RelativeTime { get; set; }
159 |
160 | [XPath("/div[@class='user-details']/a","href")]
161 | public string UserLink { get; set; }
162 |
163 | [XPath("/div[@class='user-details']/a")]
164 | public string UserName { get; set; }
165 |
166 | [XPath("/div[@class='user-details']/div[1]")]
167 | public string ReputationScore { get; set; }
168 | }
169 |
170 | [HasXPath]
171 | [DebuggerDisplay("Question Title={QuestionTitle}")]
172 | public class HotNetworkQuestion
173 | {
174 | [XPath("/div", "title")]
175 | public string QuestionCategory { get; set; }
176 |
177 | [XPath("/a")]
178 | public string QuestionTitle { get; set; }
179 |
180 | [XPath("/a", "href")]
181 | public string QuestionLink { get; set; }
182 | }
183 |
184 | #endregion #region StackOverFlow_TestClasses
185 |
186 |
187 |
188 | #region Dictionary_TestClasses
189 |
190 | [HasXPath]
191 | [DebuggerDisplay("Word={Text}")]
192 | public class Word
193 | {
194 | [XPath("//*[@id='content-wrapper']/div/h1/text()")]
195 | public string Text { get; set; }
196 |
197 | [XPath("//*[@id='accordion']/div")]
198 | public List Defs { get; set; } = new List();
199 | }
200 |
201 | [HasXPath]
202 | [DebuggerDisplay("{Deu} : {Fa}")]
203 | public class Def
204 | {
205 |
206 | [XPath("/div[1]/div[@class='panel-title definition']/a/span[@class='de']")]
207 | public string Deu { get; set; }
208 |
209 |
210 |
211 | [XPath("/div[1]/div[@class='panel-title definition']/a/span[@class='fa']")]
212 | public string Fa { get; set; }
213 |
214 | [SkipNodeNotFound]
215 | [XPath("/div[2]/div[@class='panel-body']/div")]
216 | public string FirstExampleAsString { get; set; }
217 |
218 | [SkipNodeNotFound]
219 | [XPath("/div[2]/div[@class='panel-body']/div")]
220 | public Example FirstExample { get; set; }
221 |
222 | [SkipNodeNotFound]
223 | [XPath("/div[2]/div[@class='panel-body']/div")]
224 | public IEnumerable ExamplesAsString { get; set; }
225 |
226 | [SkipNodeNotFound]
227 | [XPath("/div[2]/div[@class='panel-body']/div")]
228 | public IEnumerable Examples { get; set; }
229 |
230 | }
231 |
232 |
233 |
234 | [HasXPath]
235 | [DebuggerDisplay("{DeuEx} : {Fa}")]
236 | public class Example
237 | {
238 |
239 |
240 | [XPath("/div[@class='row']/div/p[@class='fa text-right']")]
241 | public string Fa { get; set; }
242 |
243 |
244 | [XPath("/div[@class='row']/div/p[@class='de text-left']")]
245 | public string DeuEx { get; set; }
246 |
247 | }
248 |
249 | #endregion Dictionary_TestClasses
250 |
251 | #region Encapsulated outer html test classes
252 |
253 | [HasXPath]
254 | public class OuterHtml
255 | {
256 | [XPath("//a", ReturnType.OuterHtml)]
257 | public List Items { get; set; }
258 |
259 | [XPath("//a[@class='single']", ReturnType.OuterHtml)]
260 | public OuterHtmlItem Item3 { get; set; }
261 |
262 |
263 | [HasXPath]
264 | public class OuterHtmlItem
265 | {
266 | [XPath("a", "href")]
267 | [SkipNodeNotFound]
268 | public string Href { get; set; }
269 |
270 | [XPath("a")]
271 | [SkipNodeNotFound]
272 | public string Name { get; set; }
273 | }
274 | }
275 | #endregion
276 | }
277 |
--------------------------------------------------------------------------------