Created
August 6, 2013 15:55
-
-
Save ciscou/6165818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import javax.xml.transform.*; | |
import javax.xml.transform.stream.*; | |
import javax.xml.validation.*; | |
/* | |
* Usage: download xsd's and sitemap | |
* $ wget http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd | |
* $ wget http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd | |
* $ wget http://kelisto.dev/news-sitemap.xml | |
* | |
* Compile me! | |
* $ javac NewsSitemapValidator.java | |
* | |
* And execute me! | |
* $ java NewsSitemapValidator | |
*/ | |
class NewsSitemapValidator { | |
private void validate(String xml, String xsd1, String xsd2) throws Exception { | |
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); | |
Schema schema = sf.newSchema(new Source[] { | |
new StreamSource(new File(xsd1)), | |
new StreamSource(new File(xsd2)) | |
}); | |
Validator v = schema.newValidator(); | |
v.validate(new StreamSource(xml)); | |
} | |
public static void main(String args[]) { | |
NewsSitemapValidator v = new NewsSitemapValidator(); | |
try { | |
v.validate("news-sitemap.xml", "sitemap-news.xsd", "sitemap.xsd"); | |
System.out.println("no errors found! :)"); | |
} catch(Exception e) { | |
System.err.println(e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment