I have created sitemap using the com.redfin.sitemapgenerator jar, now I want to add nodes i.e the urls in the urlset at run time, I have checked that the sitemap already exists or not but now I am unable to append to the already existing sitemap.xml file.`public String searchforques() throws IllegalArgumentException { // TODO Auto-generated method stub System.out.println("calledd");
WebSitemapGenerator sitemapGenerator = null;
WebSitemapUrl sitemapUrl = null;
File file=new File("C:\\sitemap\\sitemap.xml");
try {
if(!file.exists())
{
sitemapGenerator = WebSitemapGenerator
.builder("http://www.testing.com", new File("C:\\sitemap"))
.gzip(false).build();
/*------------------------------------------*/
try {
sitemapUrl = new WebSitemapUrl.Options(
"http://www.testing.com/#!dashboard1")
.lastMod(new Date()).priority(1.0)
.changeFreq(ChangeFreq.HOURLY).build();
System.out.println("-----------");
System.out.println("sitemapUrl :: "+sitemapUrl.getUrl());
sitemapGenerator.addUrl(sitemapUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/****************/
}
else
{
System.out.println("file already exist");
sitemapGenerator = WebSitemapGenerator
.builder("http://www.testing.com", file)
.gzip(false).build();
try {
sitemapGenerator
.addUrl("http://www.testing.com/#!ques");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("sitemapGenerator :: "+sitemapGenerator);
}
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
sitemapGenerator.write();
// this will configure the URL with lastmod=now, priority=1.0,
// changefreq=hourly
// You can add any number of urls here
return "";
}
But my else part is not working it directly goes to server fail.
I am working on java with gwt. So, any one could help to add dynamically the nodes(urls) in the urlset at runtime.