Advertisement
Guest User

Source 2

a guest
Aug 28th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3.  
  4. import nu.xom.Builder;
  5. import nu.xom.Document;
  6. import nu.xom.Element;
  7. import nu.xom.Elements;
  8. import nu.xom.ParsingException;
  9. import nu.xom.ValidityException;
  10.  
  11.  
  12. public class PartsLister {
  13.  
  14.     public static void main(String[] args) {
  15.         File root = new File("res/names");
  16.         File[] files = root.listFiles();
  17.         for(File xmlFile : files) {
  18.             String fileName = xmlFile.getName();
  19.             System.out.print(fileName.substring(0, fileName.length() - 4) + '\t');
  20.             printPartName(xmlFile);
  21.             System.out.print('\n');
  22.         }
  23.     }
  24.  
  25.     private static void printPartName(File xmlFile) {
  26.         Builder builder = new Builder();
  27.         try {
  28.             Document doc = builder.build(xmlFile);
  29.             Element root = doc.getRootElement();
  30.             Element annotations = root.getFirstChildElement("Annotations");
  31.             Elements annotationElements = annotations.getChildElements();
  32.             Element partName = annotationElements.get(1);
  33.             System.out.print(partName.getAttributeValue("designname"));
  34.         } catch (ValidityException e) {
  35.             e.printStackTrace();
  36.         } catch (ParsingException e) {
  37.             e.printStackTrace();
  38.         } catch (IOException e) {
  39.             e.printStackTrace();
  40.         }
  41.            
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement