Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.xpath.XPath;
- import javax.xml.xpath.XPathConstants;
- import javax.xml.xpath.XPathExpression;
- import javax.xml.xpath.XPathFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.NodeList;
- public class Main
- {
- public static void main(String[] args) throws Exception
- {
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- domFactory.setNamespaceAware(true);
- DocumentBuilder builder = domFactory.newDocumentBuilder();
- Document doc = builder.parse("input.xml");
- XPath xpath = XPathFactory.newInstance().newXPath();
- XPathExpression expr = xpath.compile("/stress_test/protocollo/utenti");
- Object result = expr.evaluate(doc, XPathConstants.NODESET);
- NodeList nodes = (NodeList) result;
- System.out.println("Ho trovato " + nodes.getLength() + " nodi");
- for (int i = 0; i < nodes.getLength(); i++)
- {
- Element utente = (Element) nodes.item(i);
- String username = xpath.evaluate("utente/username", utente);
- String password = xpath.evaluate("utente/password", utente);
- System.out.println(username + " " + password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement