Skip to content

Instantly share code, notes, and snippets.

@todvora
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todvora/490895c9e596e51f88d1 to your computer and use it in GitHub Desktop.
Save todvora/490895c9e596e51f88d1 to your computer and use it in GitHub Desktop.
JSOUP
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main {
public static final String INPUT = "<Snapshot id=\"142102345\">" +
"<Stats name=\"runtime\" statType=\"moduleRuntime\" il=\"-2\">" +
"<CS id=\"2\" sT=\"1422004481541\" lST=\"1427376591432\" ct=\"225331\"></CS>" +
"<CS id=\"3\" sT=\"1422004481541\" lST=\"1427376591432\" ct=\"503459\"></CS>" +
"<CS id=\"5\" sT=\"1422004481541\" lST=\"1427376591432\" ct=\"0\"></CS>" +
"</Stats>" +
"</Snapshot>";
public static void main(String[] args) {
Document doc = Jsoup.parse(INPUT);
final Elements elements = doc.select("CS"); // CSS selector
for(Element e : elements) {
System.out.println(e.attr("id") + ":" + e.attr("ct"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment