Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import nu.xom.Builder;
- import nu.xom.Document;
- import nu.xom.Element;
- import nu.xom.Elements;
- import nu.xom.ParsingException;
- import nu.xom.ValidityException;
- public class PartsLister {
- public static void main(String[] args) {
- File root = new File("res/names");
- File[] files = root.listFiles();
- for(File xmlFile : files) {
- String fileName = xmlFile.getName();
- System.out.print(fileName.substring(0, fileName.length() - 4) + '\t');
- printPartName(xmlFile);
- System.out.print('\n');
- }
- }
- private static void printPartName(File xmlFile) {
- Builder builder = new Builder();
- try {
- Document doc = builder.build(xmlFile);
- Element root = doc.getRootElement();
- Element annotations = root.getFirstChildElement("Annotations");
- Elements annotationElements = annotations.getChildElements();
- Element partName = annotationElements.get(1);
- System.out.print(partName.getAttributeValue("designname"));
- } catch (ValidityException e) {
- e.printStackTrace();
- } catch (ParsingException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement