Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- public class main {
- public static void main(String args[]) throws Exception
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document =
- builder.parse(
- ClassLoader.getSystemResourceAsStream("boots.xml"));
- //List<Boot> bootList = new ArrayList<>();
- NodeList nodeList = document.getDocumentElement().getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++)
- {
- Node node = nodeList.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element elem = (Element)node;
- Element stat = (Element)elem.getChildNodes().item(1);
- String name = elem.getAttribute("name");
- int code = Integer.parseInt( elem.getAttribute("code"), 2);
- String atr = stat.getAttribute("name");
- double val = Double.parseDouble(( stat.getTextContent()));
- //bootList.add(new Boot(name, code, atr, val));
- System.out.println(new Boot(name, code, atr, val));
- }
- }
- }
- }
- class Boot
- {
- private String Name, Atr;
- private int Code;
- private double Val;
- public Boot( String name, int code , String atr, double val)
- {
- Name = name;
- Code = code;
- Atr = atr;
- Val = val;
- }
- public String toString()
- {
- return "Boots: " + Name + " Code: " + Code + " Stat: " + Atr + " " + Val;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment