Retrieve the Sitemap URL for an HTML Document in Java

Sitemaps allow a webmaster to provide search engines with a list of URLs on a website that are available for crawling. If you need to get the sitemap URL of an HTML document, we are going demonstrate an easy API solution that can be run in Java to automate the process.

To kick things off, we will add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next we will add a reference to the dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.90</version>
</dependency>
</dependencies>

Now we’re ready to call the function with the following code:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.EditHtmlApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
EditHtmlApi apiInstance = new EditHtmlApi();
File inputFile = new File("/path/to/inputfile"); // File | Optional: Input file to perform the operation on.
String inputFileUrl = "inputFileUrl_example"; // String | Optional: URL of a file to operate on as input.
try {
HtmlGetSitemapUrlResult result = apiInstance.editHtmlHtmlGetSitemap(inputFile, inputFileUrl);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EditHtmlApi#editHtmlHtmlGetSitemap");
e.printStackTrace();
}

To retrieve your API key, visit the Cloudmersive website and register for a free account; this will provide 800 calls/month across hundreds of APIs.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.