daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <savedPositions>
  2.   <savedPosition>
  3.     <nBehaviour>nBehaviour1</nBehaviour>
  4.     <aBehaviour>aBehaviour1</aBehaviour>
  5.     <findings>findings1</findings>
  6.     <forces>forces1</forces>
  7.     <gap>gap1</gap>
  8.     <position1>0.6488889</position1>
  9.     <position2>-1000.0</position2>
  10.   </savedPosition>
  11.   <savedPosition>
  12.     <nBehaviour>nBehaviour2</nBehaviour>
  13.     <aBehaviour>aBehaviour2</aBehaviour>
  14.     <findings>findings2</findings>
  15.     <forces>aBehaviour2</forces>
  16.     <gap>gap2</gap>
  17.     <position1>-1000.0</position1>
  18.     <position2>-1000.0</position2>
  19.   </savedPosition>
  20. </savedPositions>
  21.    
  22. public class XmlToObject {
  23.  
  24.     public static ArrayList<ArrayList<String>> main() {
  25.  
  26.         ArrayList<ArrayList<String>> obj1 = new ArrayList<ArrayList<String>>();
  27.         ArrayList<ArrayList<String>> obj = new ArrayList<ArrayList<String>>();
  28.  
  29.         try {
  30.             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  31.             DocumentBuilder db = dbf.newDocumentBuilder();
  32.             Document d = db.parse("/home/nicolas/savedPos.xml");
  33.             XPath xp = XPathFactory.newInstance().newXPath();
  34.             NodeList nl = (NodeList) xp.compile("//savedPosition").evaluate(d, XPathConstants.NODESET);
  35.             System.out.println("number of saved positions " + nl.getLength());
  36.  
  37.             for (int i = 0; i < nl.getLength(); i++) {
  38.  
  39.                 String a = (xp.compile("./nBehaviour").evaluate(nl.item(i)));
  40.                 String b = (xp.compile("./aBehaviour").evaluate(nl.item(i)));
  41.                 String c = (xp.compile("./gap").evaluate(nl.item(i)));
  42.                 String d1 = (xp.compile("./forces").evaluate(nl.item(i)));
  43.                 String e = (xp.compile("./findings").evaluate(nl.item(i)));
  44.                 String f = (xp.compile("./position1").evaluate(nl.item(i)));
  45.                 String g = (xp.compile("./position2").evaluate(nl.item(i)));
  46.  
  47.                 ArrayList<String> savedPosition = new ArrayList<String>();
  48.                 savedPosition.add(a);
  49.                 savedPosition.add(b);
  50.                 savedPosition.add(c);
  51.                 savedPosition.add(d1);
  52.                 savedPosition.add(e);
  53.                 savedPosition.add(f);
  54.                 savedPosition.add(g);
  55.  
  56.                 obj.add(savedPosition);
  57.  
  58.             }
  59.  
  60.             return obj;
  61.  
  62.         } catch (Exception l) {
  63.             System.out.println(l.getMessage());
  64.         }
  65.  
  66.         return obj1;
  67.     }
  68. }
  69.    
  70. load.addActionListener(new ActionListener() {
  71.     @Override
  72.     public void actionPerformed(ActionEvent e) {
  73.  
  74.         ArrayList<ArrayList<String>> obj = XmlToObject.main();
  75.  
  76.         for(ArrayList<String> r: obj){
  77.             for(int i = 0; i < r.size(); i++){
  78.                 System.out.println(r.get(i) + "");
  79.             }
  80.             textArea.setText(r.get(0));
  81.             textArea1.setText(r.get(1));
  82.             textArea2.setText(r.get(2));
  83.             textArea3.setText(r.get(3));
  84.             textArea4.setText(r.get(4));
  85.             mediaPlayerComponent.getMediaPlayer().setPosition(Float.parseFloat(r.get(5)));
  86.             mediaPlayerComponent2.getMediaPlayer().setPosition(Float.parseFloat(r.get(6)));
  87.         }
  88.     }
  89. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top