HTML Navigation – Java Examples

Data Extraction, also well known as web data extraction, is used for extracting data from websites. A Data Extraction software will help you to automate the process of extracting data based on your requirements. Using Aspose.HTML class library, you can easily create your own application, since our API provides a powerful toolset to analyze and collect information from HTML documents.

HTML navigation

There are many ways that can be used to make HTML navigation. The following shortlist shows the simplest way to access to all DOM elements:

PropertyDescription
FirstChildAccessing this attribute of an element must return a reference to the first child node.
LastChildAccessing this attribute of an element must return a reference to the last child node
NextSiblingAccessing this attribute of an element must return a reference to the sibling node of that element which most immediately follows that element.
PreviousSiblingAccessing this attribute of an element must return a reference to the sibling node of that element which most immediately precedes that element.
ChildNodesReturns a list that contains all children of that element.

Using the mentioned properties, you can navigate through an HTML document as it follows:

For the more complicated scenarios, when you need to find a node based on a specific pattern (e.g., get the list of headers, links, etc.), you can use a specialized TreeWalker or NodeIterator object with a custom Filter implementation.

The next example shows how to implement your own NodeFilter to skip all elements except images:

Once you implement a filter, you can use HTML navigation as it follows:

XPath

The alternative to the HTML Navigation is XML Path Language. The syntax of the XPath expressions is quite simple and what is more important, it is easy to read and support.

The following example shows how to use XPath queries within Aspose.HTML API::

CSS Selector

Along with HTML Navigation and XPath you can use CSS Selector API that is also supported by our library. This API is designed to create a search pattern to match elements in a document tree based on CSS Selectors syntax.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.