private static Command parseCommand(Node n) { NamedNodeMap atts = n.getAttributes(); String name = atts.getNamedItem("name").getNodeValue(); String desc = atts.getNamedItem("description").getNodeValue(); String command = atts.getNamedItem("command").getNodeValue(); Command com = new Command(name, desc, command); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (!child.getNodeName().equals("Argument")) continue; NamedNodeMap childAtts = child.getAttributes(); String childName = childAtts.getNamedItem("name").getNodeValue(); String childDesc = childAtts.getNamedItem("description").getNodeValue(); String childVal = ""; if (childAtts.getNamedItem("default") != null) childVal = childAtts.getNamedItem("default").getNodeValue(); Argument arg = new Argument(childName, childDesc, childVal); com.addArgument(arg); } return com; }
private static void parseNode(Node n, Category parent) { String name = n.getNodeName(); if (name.equals("Category")) { Category cat = parseCategory(n); parent.addCategory(cat); } if (name.equals("Command")) { Command com = parseCommand(n); parent.addCommand(com); } }