Skip to content

Instantly share code, notes, and snippets.

@marchermans
Created February 15, 2019 08:40
Show Gist options
  • Save marchermans/3894f9fe363c0b010984eb2aea47d7e3 to your computer and use it in GitHub Desktop.
Save marchermans/3894f9fe363c0b010984eb2aea47d7e3 to your computer and use it in GitHub Desktop.
Parser for maven-metadata.xml
public List<String> parse(URL link) throws IOException, ParserConfigurationException, SAXException
{
final List<String> versions = Lists.newArrayList();
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(link.openStream());
NodeList versionNodes = document.getElementsByTagName("version");
for (int i = 0; i < versionNodes.getLength(); i++)
{
Node versionNode = versionNodes.item(i);
versions.add(versionNode.getTextContent());
}
return versions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment