alastor1729 / sitemapgen4j

Automatically exported from code.google.com/p/sitemapgen4j
0 stars 0 forks source link

jdom integration #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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);

Original issue reported on code.google.com by ban...@gmail.com on 16 Mar 2010 at 2:17

GoogleCodeExporter commented 8 years ago
Could you please open a pull request with the fix at 
https://github.com/dfabulich/sitemapgen4j ?

Original comment by m.k...@irregular.at on 20 Mar 2015 at 10:06