Get the avaliable XPaths of an Html page?



I've taken and adapted this code of how to retrieve the XPath expressions of an XML document.


I Would like to do the same but using an html page to retrieve its avaliable XPaths ( maybe an HtmlDocument? ), is this possibly?


Note: I can accept a native solution or else using HtmlAgilityPack library.


This is the XML method:



''' <summary>
''' Gets all the XPath expressions of an XML Document.
''' </summary>
''' <param name="Document">Indicates the XML document.</param>
''' <returns>List(Of System.String).</returns>
Public Function GetXPaths(ByVal Document As Xml.XmlDocument) As List(Of String)

Dim XPathList As New List(Of String)

Dim XPath As String = String.Empty

For Each Child As Xml.XmlNode In Document.ChildNodes

If Child.NodeType = Xml.XmlNodeType.Element Then
GetXPaths(Child, XPathList, XPath)
End If

Next ' child

Return XPathList

End Function

''' <summary>
''' Gets all the XPath expressions of an XML Node.
''' </summary>
''' <param name="Node">Indicates the XML node.</param>
''' <param name="XPathList">Indicates a ByReffered XPath list as a <see cref="List(Of String)"/>.</param>
''' <param name="XPath">Indicates the current XPath.</param>
Private Sub GetXPaths(ByVal Node As Xml.XmlNode,
ByRef XPathList As List(Of String),
Optional ByVal XPath As String = Nothing)

XPath &= "/" & Node.Name

If Not XPathList.Contains(XPath) Then
XPathList.Add(XPath)
End If

For Each Child As Xml.XmlNode In Node.ChildNodes

If Child.NodeType = Xml.XmlNodeType.Element Then
GetXPaths(Child, XPathList, XPath)
End If

Next ' child

End Sub

No comments:

Post a Comment