Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created September 21, 2009 16:05
Show Gist options
  • Save jaydonnell/190345 to your computer and use it in GitHub Desktop.
Save jaydonnell/190345 to your computer and use it in GitHub Desktop.
XPath xpath = XPathFactory.newInstance().newXPath();
String xmlFile = "Wikipedia-Category-GlobalWarming-20090919043526.xml";
InputStream is = WikipediaSeederTest.class.getClassLoader().getResourceAsStream(xmlFile);
InputSource inputSource = new InputSource( is );
NamespaceContext context = new NamespaceContextMap("wp", "http://www.mediawiki.org/xml/export-0.3/");
xpath.setNamespaceContext(context);
NodeList elements = (NodeList)xpath.evaluate(
"//wp:page", inputSource, XPathConstants.NODESET );
System.out.println("length: " + elements.getLength());
for( int i=0; i<elements.getLength(); i++ ) {
// do stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment