What is the intentional use of the HtmlAgilityPack MixedCodeDocument?

I am using version 1.4 of HtmlAgilityPack, and as I understand it, MixedCodeDocument and its related classes will help you parse asp.net markup as found in aspx and ascx files. I found zero documentation or examples for the MixedCodeDocument class. From what I tried, it seems that MixedCodeDocument breaks the text of the file into pieces, separating asp.net fragments from nonasp.net fragments. For example, the following snippet:

<asp:Label ID="lbl_xyz" runat="server" Text='<%=Name%>'></asp:Label> <a href='#'>blah</a> 

will be broken down into:

 // Text fragment 1 <asp:Label ID="lbl_xyz" runat="server" Text=" // Code fragment 1 <%=Name%> // Text fragment 2 (two lines) ></asp:Label> <a href='#'>blah</a> 

But no parsing goes deeper than that, i.e. the a tag is not parsed into its own node with attributes or something like that.

Therefore, I assume that MixedCodeDocument will be used to highlight code fragments so that the remaining text fragments can be put together and then parsed using the HtmlDocument class.

Does anyone know if this is correct? Or even better, does anyone have any tips on how to successfully parse and manage an aspx or ascx file using HAP or another?

+4
source share
1 answer

You assume that it is 100% correct.

The MixedCodeDocument class was designed to be able to parse text containing two languages, that is, classic ASP, ASP.NET, etc., therefore, the name MixedCodeDocument

Initially, the Html Agility Pack was used in a tool that is able to process and convert a whole tree of various files, including HTML and other types of files. If you needed to replace only parts of HTML for other files, this class helped you to separate code and markup and. The separated codes and markup blocks can then be analyzed in other ways.

I don’t think anyone is using it today :)

+1
source

All Articles