title: read XML file from assets folder for tree view?
body: <p>Hi need to run a hierarchical file which is in assets folder in tree view . I did submit Folderstucture fragemets here also.
  Actually i have to pass  the data without making any hard code you can see in case 1 ()... Please help me .Sorry for bad example any needs i can provide you again hard copy.<br>
  trying hard to do it . Please give me an example for android studio. Thank you.</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;de&gt;
      &lt;haw_hamburg&gt;
                  &lt;bt7&gt;
                      &lt;r1485&gt;
                          &lt;devices&gt;
                              &lt;device id='135165'&gt;
                                  &lt;device_name&gt;TV living room&lt;/device_name&gt;
                                  &lt;id_type&gt;1&lt;/id_type&gt;
                                  &lt;id_type_device&gt;1&lt;/id_type_device&gt;
                                  &lt;model&gt;SmartTV LED  47"&lt;/model&gt;
                                  &lt;owner&gt;&lt;/owner&gt;
                                  &lt;connectivity&gt;wifi&lt;/connectivity&gt;
                                  &lt;address&gt;192.168.1.100&lt;/address&gt;
                                  &lt;info&gt;
                                      &lt;screen&gt;
                                          &lt;height&gt;1080&lt;/height&gt;
                                          &lt;width&gt;1920&lt;/width&gt;
                                      &lt;/screen&gt;
                                      &lt;speaker&gt;true&lt;/speaker&gt;
                                      &lt;input&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;sensortype&gt;&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                      &lt;/input&gt;
                                      &lt;output&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;actuatortype&gt;&lt;/actuatortype&gt;
                                          &lt;/item&gt;
                                      &lt;/output&gt;
                                      &lt;wifi&gt;
                                          &lt;mac&gt;3C:CD:93:74:62:56&lt;/mac&gt;
                                      &lt;/wifi&gt;
                                      &lt;ethernet&gt;
                                          &lt;mac_eth&gt;4D:CF:93:23:61:17&lt;/mac_eth&gt;
                                      &lt;/ethernet&gt;
                                      &lt;rf&gt;false&lt;/rf&gt;
                                  &lt;/info&gt;
                              &lt;/device&gt;
                              &lt;device id='165165'&gt;
                                  &lt;device_name&gt;TV room&lt;/device_name&gt;
                                  &lt;id_type&gt;1&lt;/id_type&gt;
                                  &lt;id_type_device&gt;1&lt;/id_type_device&gt;
                                  &lt;model&gt;SmartTV LED  28"&lt;/model&gt;
                                  &lt;owner&gt;&lt;/owner&gt;
                                  &lt;connectivity&gt;eth&lt;/connectivity&gt;
                                  &lt;address&gt;&lt;/address&gt;
                                  &lt;info&gt;
                                      &lt;screen&gt;
                                          &lt;height&gt;768&lt;/height&gt;
                                          &lt;width&gt;1366&lt;/width&gt;
                                      &lt;/screen&gt;
                                      &lt;speaker&gt;true&lt;/speaker&gt;
                                      &lt;input&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;sensortype&gt;&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                      &lt;/input&gt;
                                      &lt;output&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;actuatortype&gt;&lt;/actuatortype&gt;
                                          &lt;/item&gt;
                                      &lt;/output&gt;
                                      &lt;wifi&gt;
                                          &lt;mac&gt;3C:CD:93:74:62:56&lt;/mac&gt;
                                      &lt;/wifi&gt;
                                      &lt;ethernet&gt;
                                          &lt;mac_eth&gt;4D:CF:93:23:61:17&lt;/mac_eth&gt;
                                      &lt;/ethernet&gt;
                                      &lt;rf&gt;false&lt;/rf&gt;
                                  &lt;/info&gt;
                              &lt;/device&gt;
                              &lt;device id='546161'&gt;
                                  &lt;device_name&gt;Temperature sensor kitchen&lt;/device_name&gt;
                                  &lt;id_type&gt;3&lt;/id_type&gt;
                                  &lt;id_type_device&gt;4&lt;/id_type_device&gt;
                                  &lt;model&gt;Sensor temperature&lt;/model&gt;
                                  &lt;owner&gt;&lt;/owner&gt;
                                  &lt;connectivity&gt;radio&lt;/connectivity&gt;
                                  &lt;address&gt;&lt;/address&gt;
                                  &lt;info&gt;
                                      &lt;screen&gt;
                                          &lt;height&gt;&lt;/height&gt;
                                          &lt;width&gt;&lt;/width&gt;
                                      &lt;/screen&gt;
                                      &lt;speaker&gt;&lt;/speaker&gt;
                                      &lt;input&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;sensortype&gt;&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                      &lt;/input&gt;
                                      &lt;output&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;actuatortype&gt;&lt;/actuatortype&gt;
                                          &lt;/item&gt;
                                      &lt;/output&gt;
                                      &lt;wifi&gt;
                                          &lt;mac&gt;3C:CD:93:74:62:56&lt;/mac&gt;
                                      &lt;/wifi&gt;
                                      &lt;ethernet&gt;
                                          &lt;mac_eth&gt;4D:CF:93:23:61:17&lt;/mac_eth&gt;
                                      &lt;/ethernet&gt;
                                      &lt;rf&gt;true&lt;/rf&gt;
                                  &lt;/info&gt;
                              &lt;/device&gt;
                              &lt;device id='459863'&gt;
                                  &lt;device_name&gt;John's Phone&lt;/device_name&gt;
                                  &lt;id_type&gt;2&lt;/id_type&gt;
                                  &lt;id_type_device&gt;3&lt;/id_type_device&gt;
                                  &lt;model&gt;Samsung Galaxy Note 4&lt;/model&gt;
                                  &lt;owner&gt;2&lt;/owner&gt;
                                  &lt;connectivity&gt;wifi&lt;/connectivity&gt;
                                  &lt;address&gt;192.168.1.100&lt;/address&gt;
                                  &lt;info&gt;
                                      &lt;screen&gt;
                                          &lt;height&gt;2560&lt;/height&gt;
                                          &lt;width&gt;1440&lt;/width&gt;
                                      &lt;/screen&gt;
                                      &lt;speaker&gt;true&lt;/speaker&gt;
                                      &lt;input&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;sensortype&gt;&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                      &lt;/input&gt;
                                      &lt;output&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;&lt;/name&gt;
                                              &lt;id&gt;&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;actuatortype&gt;&lt;/actuatortype&gt;
                                          &lt;/item&gt;
                                      &lt;/output&gt;
                                      &lt;wifi&gt;
                                          &lt;mac&gt;3C:CD:93:74:62:56&lt;/mac&gt;
                                      &lt;/wifi&gt;
                                      &lt;ethernet&gt;
                                          &lt;mac_eth&gt;&lt;/mac_eth&gt;
                                      &lt;/ethernet&gt;
                                      &lt;rf&gt;false&lt;/rf&gt;
                                  &lt;/info&gt;
                              &lt;/device&gt;
                              &lt;device id='189964'&gt;
                                  &lt;device_name&gt;Heating&lt;/device_name&gt;
                                  &lt;id_type&gt;1&lt;/id_type&gt;
                                  &lt;id_type_device&gt;5&lt;/id_type_device&gt;
                                  &lt;model&gt;Mitsubishi Electric&lt;/model&gt;
                                  &lt;owner&gt;&lt;/owner&gt;
                                  &lt;connectivity&gt;wifi&lt;/connectivity&gt;
                                  &lt;address&gt;192.168.1.28&lt;/address&gt;
                                  &lt;info&gt;
                                      &lt;screen&gt;
                                          &lt;height&gt;&lt;/height&gt;
                                          &lt;width&gt;&lt;/width&gt;
                                      &lt;/screen&gt;
                                      &lt;speaker&gt;&lt;/speaker&gt;
                                      &lt;input&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;Humidity sensor&lt;/name&gt;
                                              &lt;id&gt;1&lt;/id&gt;
                                              &lt;unit&gt;mb&lt;/unit&gt;
                                              &lt;sensortype&gt;1&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;Temperature sensor&lt;/name&gt;
                                              &lt;id&gt;2&lt;/id&gt;
                                              &lt;unit&gt;ยบC&lt;/unit&gt;
                                              &lt;sensortype&gt;2&lt;/sensortype&gt;
                                          &lt;/item&gt;
                                      &lt;/input&gt;
                                      &lt;output&gt;
                                          &lt;item&gt;
                                              &lt;name&gt;RGB led lights&lt;/name&gt;
                                              &lt;id&gt;3&lt;/id&gt;
                                              &lt;unit&gt;&lt;/unit&gt;
                                              &lt;actuatortype&gt;1&lt;/actuatortype&gt;
                                          &lt;/item&gt;
                                      &lt;/output&gt;
                                      &lt;wifi&gt;
                                          &lt;mac&gt;3C:XD:93:94:61:46&lt;/mac&gt;
                                      &lt;/wifi&gt;
                                      &lt;ethernet&gt;
                                          &lt;mac_eth&gt;&lt;/mac_eth&gt;
                                      &lt;/ethernet&gt;
                                      &lt;rf&gt;false&lt;/rf&gt;
                                  &lt;/info&gt;
                              &lt;/device&gt;
                          &lt;/devices&gt;
                      &lt;/r1485&gt;
                  &lt;/bt7&gt;
      &lt;/haw_hamburg&gt;
  &lt;/de&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>package haw.com.smarthomelib;
  import android.app.Fragment;
  import android.os.Bundle;
  import android.text.TextUtils;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.w3c.dom.Element;
  import java.io.File;
  public class FolderStructureFragment extends Fragment {
  
      private TextView statusBar;
      private AndroidTreeView tView;
      private String Type;
      private String Value;
      private int check = 1;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(true);
      }
  
      @Override
      /**
       * setContentView(int) with a layout resource defining our UI
       * using findViewById(int) to retrieve the widgets in that UI
       * that we need to interact with
       */
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_default, null, false);
          ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container);
          statusBar = (TextView) rootView.findViewById(R.id.status_bar);
          TreeNode root = TreeNode.root();
          TreeNode Country = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_location, "Germany",""));
  
          TreeNode City = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_location_city, "Hamburg",""));
          TreeNode University = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_gps_fixed, "HAW Hamburg",""));
          TreeNode Buliding1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_gps_not_fixed, "Berliner Tor 1",""));
          TreeNode Building2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_gps_not_fixed, "Berliner Tor 3",""));
          TreeNode Building3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_gps_not_fixed, "Berliner Tor 5",""));
          TreeNode Building4 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_hotel, "Berliner Tor 7",""));
          University.addChildren(Buliding1, Building2, Building3, Building4);
  
          TreeNode ServerRoom = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_laptop, "Server room",""));
          TreeNode ProjectGroup1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_group, "Group 1",""));
          //TreeNode ProjectGroup2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_group, "Group 2",""));
         // TreeNode ProjectGroup3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_group, "Group 3",""));
          //TreeNode ProjectGroup4 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_group, "Group 4",""));
          City.addChild(University);
          Country.addChildren(City);
          root.addChildren(Country);
          Building4.addChild(ServerRoom);
         // ServerRoom.addChildren(ProjectGroup1, ProjectGroup2, ProjectGroup3, ProjectGroup4);
          ServerRoom.addChildren(ProjectGroup1);
          fillFolder(ProjectGroup1);
         // fillFolder(ProjectGroup2);
          tView = new AndroidTreeView(getActivity(), root);
          tView.setDefaultAnimation(true);
          // 2Dscroll
          //tView.setUse2dScroll(true);
          tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
          tView.setDefaultViewHolder(IconTreeItemHolder.class);
          tView.setDefaultNodeClickListener(nodeClickListener);
          tView.setDefaultNodeLongClickListener(nodeLongClickListener);
          containerView.addView(tView.getView());
  
          if (savedInstanceState != null) {
              String state = savedInstanceState.getString("tState");
              if (!TextUtils.isEmpty(state)) {
                  tView.restoreState(state);
              }
          }
  
          return rootView;
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          inflater.inflate(R.menu.menu, menu);
          super.onCreateOptionsMenu(menu, inflater);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.expandAll:
                  tView.expandAll();
                  break;
  
              case R.id.collapseAll:
                  tView.collapseAll();
                  break;
          }
          return true;
      }
  
      private void fillFolder(TreeNode folder) {
  
          switch (check) {
  
              case 1: {
                  TreeNode file1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_check_circle_blank, "TempIn", "-5°c"));
                  TreeNode file2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_check_circle_blank, "TempOut", "25°c"));
                  TreeNode file3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_check_circle_blank, "Humidity", "35%"));
                  TreeNode file4 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_check_circle_blank, "Battery", "62%"));
  
                  folder.addChildren(file1, file2, file3,file4 );
                  break;
              }
  
              case 2:
                  try {
                      //System.out.println("----------------------------");
                      File fXmlFile = new File("/Users/student/Desktop/Configuration.xml");
                      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                      Document doc = dBuilder.parse(fXmlFile);
                      doc.getDocumentElement().normalize();
                      // System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
                      NodeList nList = doc.getElementsByTagName("Sensors");
                      //System.out.println("----------------------------");
                      for (int temp = 0; temp &lt; nList.getLength(); temp++) {
                          Node nNode = nList.item(temp);
                          //System.out.println("\nCurrent Element :" + nNode.getNodeName());
                          if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                              Element eElement = (Element) nNode;
                              //System.out.println("Sensors id : "
                              //        + eElement.getAttribute("id"));
                              Type = eElement.getElementsByTagName("type")
                                      .item(0).getTextContent();
                              Value = eElement.getElementsByTagName("value")
                                      .item(0).getTextContent();
                              TreeNode file = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_check_circle_blank, Type, Value));
                              folder.addChildren(file);
                          }
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
          }
      }
  
      private TreeNode.TreeNodeClickListener nodeClickListener = new TreeNode.TreeNodeClickListener() {
          @Override
          public void onClick(TreeNode node, Object value) {
              IconTreeItemHolder.IconTreeItem item = (IconTreeItemHolder.IconTreeItem) value;
              statusBar.setText("Last clicked: " + item.text);
          }
      };
  
      private TreeNode.TreeNodeLongClickListener nodeLongClickListener = new TreeNode.TreeNodeLongClickListener() {
          @Override
          public boolean onLongClick(TreeNode node, Object value) {
              IconTreeItemHolder.IconTreeItem item = (IconTreeItemHolder.IconTreeItem) value;
              Toast.makeText(getActivity(), "Long click: " + item.text, Toast.LENGTH_SHORT).show();
              return true;
          }
      };
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putString("tState", tView.getSaveState());
      }
  }
  </code></pre>