Tutorial

Using Sitemaps for Java is pretty strait forward, as shown in the example below. Sitemaps for Java currently supports two strategies in Sitemap-creation:

Sitemaps can be created as compressed Sitemaps with the setCompressed() to true, and if validation of the result is required set setValidationIncluded() to true.


// ...
try {
  // Create Sitemaps for example.com
  Sitemaps sitemaps = new Sitemaps(
       new java.net.URL("http://www.example.com"),
             new File("C:/homedir/example.com/"));

  // Compress the sitemaps
  sitemaps.setCompressed(false);

  // Without validation
  sitemaps.setValidationIncluded(false);

  // Now add URLs
  URL url1 = new URL(
      new java.net.URL("http://www.example.com/index.html"),
      new Date(System.currentTimeMillis()),
      ChangeFrequency.ALWAYS, 1.0);


  sitemaps.addURL(url1);

  URL url2 = new URL(
      new java.net.URL("http://www.example.com/faq.html"),
      new Date(System.currentTimeMillis()),
      ChangeFrequency.HOURLY, 0.75);  

  sitemaps.addURL(url2);

  // Close sitemaps and write - also writes Sitemap Index
  sitemaps.close();
} catch (Exception e) {
  e.printStackTrace();
}
//..

The Javadocs give an overview of the API.