1- // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
1+ // Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
22// Website & Documentation: http://html-agility-pack.net
33// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
44// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
55// More projects: http://www.zzzprojects.com/
6- // Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
6+ // Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
77
88#if ! METRO && ! NETSTANDARD1_3
99
@@ -29,7 +29,7 @@ public partial class HtmlNode
2929 /// <exception cref="XPathException">Why it's thrown.</exception>
3030 /// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
3131 /// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
32- /// <exception cref="FormatException">Why it's thrown.</exception>
32+ /// <exception cref="FormatException">Why it's thrown.</exception>
3333 /// <exception cref="Exception">Why it's thrown.</exception>
3434 public T GetEncapsulatedData < T > ( )
3535 {
@@ -50,7 +50,7 @@ public T GetEncapsulatedData<T>()
5050 /// <exception cref="XPathException">Why it's thrown.</exception>
5151 /// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
5252 /// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
53- /// <exception cref="FormatException">Why it's thrown.</exception>
53+ /// <exception cref="FormatException">Why it's thrown.</exception>
5454 /// <exception cref="Exception">Why it's thrown.</exception>
5555 public T GetEncapsulatedData < T > ( HtmlDocument htmlDocument )
5656 {
@@ -72,7 +72,7 @@ public T GetEncapsulatedData<T>(HtmlDocument htmlDocument)
7272 /// <exception cref="XPathException">Why it's thrown.</exception>
7373 /// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
7474 /// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
75- /// <exception cref="FormatException">Why it's thrown.</exception>
75+ /// <exception cref="FormatException">Why it's thrown.</exception>
7676 /// <exception cref="Exception">Why it's thrown.</exception>
7777 public object GetEncapsulatedData ( Type targetType , HtmlDocument htmlDocument = null )
7878 {
@@ -177,7 +177,7 @@ public object GetEncapsulatedData(Type targetType, HtmlDocument htmlDocument = n
177177 {
178178 HtmlDocument innerHtmlDocument = new HtmlDocument ( ) ;
179179
180- innerHtmlDocument . LoadHtml ( htmlNode . InnerHtml ) ;
180+ innerHtmlDocument . LoadHtml ( GetEncapsulatedHtml ( xPathAttribute . NodeReturnType , htmlNode ) ) ;
181181
182182 object o = GetEncapsulatedData ( propertyInfo . PropertyType , innerHtmlDocument ) ;
183183
@@ -192,7 +192,7 @@ public object GetEncapsulatedData(Type targetType, HtmlDocument htmlDocument = n
192192 {
193193 string result = string . Empty ;
194194
195- if ( xPathAttribute . AttributeName == null ) // It target value of HTMLTag
195+ if ( xPathAttribute . AttributeName == null ) // It target value of HTMLTag
196196 {
197197 result = Tools . GetNodeValueBasedOnXPathReturnType < string > ( htmlNode , xPathAttribute ) ;
198198 }
@@ -295,7 +295,7 @@ public object GetEncapsulatedData(Type targetType, HtmlDocument htmlDocument = n
295295 foreach ( HtmlNode node in nodeCollection )
296296 {
297297 HtmlDocument innerHtmlDocument = new HtmlDocument ( ) ;
298- innerHtmlDocument . LoadHtml ( node . InnerHtml ) ;
298+ innerHtmlDocument . LoadHtml ( GetEncapsulatedHtml ( xPathAttribute . NodeReturnType , node ) ) ;
299299
300300 object o = GetEncapsulatedData ( T_Types [ 0 ] , innerHtmlDocument ) ;
301301
@@ -384,6 +384,20 @@ public object GetEncapsulatedData(Type targetType, HtmlDocument htmlDocument = n
384384
385385
386386
387+ private static string GetEncapsulatedHtml ( ReturnType returnType , HtmlNode node )
388+ {
389+ switch ( returnType )
390+ {
391+ case ReturnType . InnerText :
392+ return node . InnerText ;
393+ case ReturnType . InnerHtml :
394+ return node . InnerHtml ;
395+ case ReturnType . OuterHtml :
396+ return node . OuterHtml ;
397+ default :
398+ throw new Exception ( "Unhandled ReturnType : " + returnType . ToString ( ) ) ;
399+ } ;
400+ }
387401 }
388402
389403
@@ -797,7 +811,7 @@ internal static int CountOfIEnumerable<T>(this IEnumerable<T> source)
797811 public enum ReturnType
798812 {
799813 /// <summary>
800- /// The text between the start and end tags of the object.
814+ /// The text between the start and end tags of the object.
801815 /// </summary>
802816 InnerText ,
803817
@@ -896,18 +910,18 @@ public sealed class SkipNodeNotFoundAttribute : Attribute
896910 public class NodeNotFoundException : Exception
897911 {
898912 /// <summary>
899- ///
913+ ///
900914 /// </summary>
901915 public NodeNotFoundException ( ) { }
902916
903917 /// <summary>
904- ///
918+ ///
905919 /// </summary>
906920 /// <param name="message"></param>
907921 public NodeNotFoundException ( string message ) : base ( message ) { }
908922
909923 /// <summary>
910- ///
924+ ///
911925 /// </summary>
912926 /// <param name="message"></param>
913927 /// <param name="inner"></param>
@@ -921,18 +935,18 @@ public NodeNotFoundException(string message, Exception inner) : base(message, in
921935 public class NodeAttributeNotFoundException : Exception
922936 {
923937 /// <summary>
924- ///
938+ ///
925939 /// </summary>
926940 public NodeAttributeNotFoundException ( ) { }
927941
928942 /// <summary>
929- ///
943+ ///
930944 /// </summary>
931945 /// <param name="message"></param>
932946 public NodeAttributeNotFoundException ( string message ) : base ( message ) { }
933947
934948 /// <summary>
935- ///
949+ ///
936950 /// </summary>
937951 /// <param name="message"></param>
938952 /// <param name="inner"></param>
@@ -947,18 +961,18 @@ public class MissingXPathException : Exception
947961 {
948962
949963 /// <summary>
950- ///
964+ ///
951965 /// </summary>
952966 public MissingXPathException ( ) { }
953967
954968 /// <summary>
955- ///
969+ ///
956970 /// </summary>
957971 /// <param name="message"></param>
958972 public MissingXPathException ( string message ) : base ( message ) { }
959973
960974 /// <summary>
961- ///
975+ ///
962976 /// </summary>
963977 /// <param name="message"></param>
964978 /// <param name="inner"></param>
@@ -967,7 +981,7 @@ public MissingXPathException(string message, Exception inner) : base(message, in
967981
968982}
969983
970- #if FX20
984+ #if FX20
971985namespace System . Runtime . CompilerServices
972986{
973987 [ AttributeUsage ( AttributeTargets . Method |
0 commit comments