title: How add element to xml file by JAXB?
body: <p>I have problem when I want add element to my XML,so I have two element project this root element and layer this element is inside element project, but I can't add layer to project element (user can add project then add more one layers),I need method layer inside element Project same my XML.</p>
  
  <p>This Project class :</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "", propOrder = {
      "layer"
  })
  @XmlRootElement(name = "Project")
  public class Project {
  
      @XmlElement(name = "Layer")
      protected List&lt;Layer&gt; layer;
      @XmlAttribute(name = "name")
      protected String name; 
  
     public List&lt;Layer&gt; getLayer() {
          if (layer == null) {
              layer = new ArrayList&lt;Layer&gt;();
          }
          return this.layer;
      }
      public String getName() {
          return name;
      }
      public void setName(String value) {
          this.name = value;
      }
  }
  </code></pre>
  
  <p>This layer class :</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  public class Layer {
      @XmlElement(name = "LayerName", required = true)
      protected String layerName;
      @XmlAttribute(name = "idLayer")
      protected int idLayer;
      public String getLayerName() {
          return layerName;
      }
      public void setLayerName(String value) {
          this.layerName = value;
      }
      public int getIdLayer() {
          return idLayer;
      }
      public void setIdLayer(int i) {
          this.idLayer = i;
      }
  }
  </code></pre>
  
  <p>This My method for insert project :</p>
  
  <pre><code> public void Insert(Project entity) {
      Project pr = new Project();
      pr.setName("pr1");
          try {
      JAXBContext jc = JAXBContext.newInstance(Project.class);
      javax.xml.bind.Marshaller marshaller = jc.createMarshaller();
      marshaller.setProperty(marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      File XMLfile = new File("Projects" + "//" + pr.getName() + "//" +"ProjectDataBase.xml");
      marshaller.marshal(pr, XMLfile);
      }
      } catch (JAXBException e) {
           e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>My XML :</p>
  
  <pre><code>   &lt;Project name="pr1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
         &lt;Layer idLayer="0"&gt;
           &lt;LayerName&gt;LayerName1&lt;/LayerName&gt;
         &lt;/Layer&gt; 
         &lt;Layer idLayer="1"&gt;
           &lt;LayerName&gt;LayerName2&lt;/LayerName&gt;
         &lt;/Layer&gt; 
      &lt;/Project&gt;
  </code></pre>