Sample on how to generate code that can be and should be subject to namespace validation:
//important imports import org.jdom.Attribute; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import org.jdom.Document; import org.jdom.Element;
//code sample Document document = new Document();
Namespace xmlns = Namespace.getNamespace("http://www.sitemaps.org/schemas/sitemap/0.9"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
Element rootElement = new Element("urlset", xmlns); rootElement.addNamespaceDeclaration(xsi); Attribute schemaLocation = new Attribute("schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9" + " http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd", xsi); rootElement.setAttribute(schemaLocation);
document.setRootElement(rootElement);
//begin url harvesting
Element url = new Element("url", xmlns);
Element loc = new Element("loc", xmlns);
Element lastmod = new Element("lastmod", xmlns);
Element changefreq = new Element("changefreq", xmlns);
Element priority = new Element("priority", xmlns);
loc.addContent("");
lastmod.addContent("");
changefreq.addContent("");
priority.addContent("");
url.addContent(loc);
url.addContent(lastmod);
url.addContent(changefreq);
url.addContent(priority);
rootElement.addContent(url);
//end loop
createSitemapFile(document);
Comment #1
Posted on Mar 20, 2015 by Helpful BirdCould you please open a pull request with the fix at https://github.com/dfabulich/sitemapgen4j ?
Status: New
Labels:
Type-Defect
Priority-Medium