title: How to remove some elements from XML file generated using JAXB?
body: <p>I have been trying to generate XML file from lists of object of type <code>Customer</code> class.
  Which i have done successfully.But the structure of my XML file is nested and i want to flatten it out.</p>
  
  <p>Following is my XML file content:</p>
  
  <pre><code>&lt;Customers&gt;
  &lt;customer&gt;
      &lt;accessRole&gt;
          &lt;name&gt;Customer Center&lt;/name&gt;
          &lt;internalId&gt;14&lt;/internalId&gt;
      &lt;/accessRole&gt;
      &lt;aging&gt;0.0&lt;/aging&gt;
      &lt;category&gt;
          &lt;name&gt;Individual&lt;/name&gt;
          &lt;internalId&gt;2&lt;/internalId&gt;
      &lt;/category&gt;
      &lt;companyName&gt;Wolfe Electronics&lt;/companyName&gt;
      &lt;consolAging&gt;0.0&lt;/consolAging&gt;
      &lt;consolBalance&gt;0.0&lt;/consolBalance&gt;
      &lt;consolDepositBalance&gt;0.0&lt;/consolDepositBalance&gt;
      &lt;consolOverdueBalance&gt;0.0&lt;/consolOverdueBalance&gt;
      &lt;consolUnbilledOrders&gt;2705.23&lt;/consolUnbilledOrders&gt;
      &lt;creditHoldOverride/&gt;
      &lt;dateCreated&gt;2011-06-22T12:30:00+05:30&lt;/dateCreated&gt;
      &lt;defaultAddress&gt;US&lt;/defaultAddress&gt;
      &lt;displaySymbol&gt;$&lt;/displaySymbol&gt;
      &lt;email&gt;suresh@ldbsystems.com&lt;/email&gt;
      &lt;emailPreference/&gt;
      &lt;emailTransactions&gt;false&lt;/emailTransactions&gt;
      &lt;entityId&gt;A Wolfe&lt;/entityId&gt;
      &lt;entityStatus&gt;
          &lt;name&gt;CUSTOMER-Closed Won&lt;/name&gt;
          &lt;internalId&gt;13&lt;/internalId&gt;
      &lt;/entityStatus&gt;
      &lt;externalId&gt;entity-5&lt;/externalId&gt;
      &lt;faxTransactions&gt;false&lt;/faxTransactions&gt;
      &lt;firstName&gt;A&lt;/firstName&gt;
      &lt;firstVisit&gt;2012-02-25T05:43:18+05:30&lt;/firstVisit&gt;
      &lt;giveAccess&gt;true&lt;/giveAccess&gt;
      &lt;globalSubscriptionStatus/&gt;
      &lt;internalId&gt;-5&lt;/internalId&gt;
      &lt;isBudgetApproved&gt;false&lt;/isBudgetApproved&gt;
      &lt;isInactive&gt;false&lt;/isInactive&gt;
      &lt;isPerson&gt;true&lt;/isPerson&gt;
      &lt;lastModifiedDate&gt;2012-12-19T07:12:03+05:30&lt;/lastModifiedDate&gt;
      &lt;lastName&gt;Wolfe&lt;/lastName&gt;
      &lt;lastPageVisited&gt;login-register&lt;/lastPageVisited&gt;
      &lt;lastVisit&gt;2013-02-23T06:10:44+05:30&lt;/lastVisit&gt;
      &lt;overrideCurrencyFormat&gt;false&lt;/overrideCurrencyFormat&gt;
      &lt;phone&gt;650-555-9788&lt;/phone&gt;
      &lt;priceLevel&gt;
          &lt;name&gt;Employee Price&lt;/name&gt;
          &lt;internalId&gt;3&lt;/internalId&gt;
      &lt;/priceLevel&gt;
      &lt;printTransactions&gt;false&lt;/printTransactions&gt;
      &lt;receivablesAccount&gt;
          &lt;name&gt;Use System Preference&lt;/name&gt;
          &lt;internalId&gt;-10&lt;/internalId&gt;
      &lt;/receivablesAccount&gt;
      &lt;salesRep&gt;
          &lt;name&gt;Clark Koozer&lt;/name&gt;
          &lt;internalId&gt;23&lt;/internalId&gt;
      &lt;/salesRep&gt;
      &lt;shipComplete&gt;false&lt;/shipComplete&gt;
      &lt;stage/&gt;
      &lt;symbolPlacement/&gt;
      &lt;taxItem&gt;
          &lt;name&gt;CA-SAN MATEO&lt;/name&gt;
          &lt;internalId&gt;-112&lt;/internalId&gt;
      &lt;/taxItem&gt;
      &lt;taxable&gt;false&lt;/taxable&gt;
      &lt;unbilledOrders&gt;2705.23&lt;/unbilledOrders&gt;
      &lt;visits&gt;150&lt;/visits&gt;
      &lt;webLead&gt;No&lt;/webLead&gt;
  &lt;/customer&gt;
  &lt;customer&gt;
      &lt;accessRole&gt;
          &lt;name&gt;Customer Center&lt;/name&gt;
          &lt;internalId&gt;14&lt;/internalId&gt;
      &lt;/accessRole&gt;
      &lt;aging&gt;0.0&lt;/aging&gt;
      &lt;category&gt;
          &lt;name&gt;Corporate&lt;/name&gt;
          &lt;internalId&gt;1&lt;/internalId&gt;
      &lt;/category&gt;
      &lt;consolAging&gt;0.0&lt;/consolAging&gt;
      &lt;consolBalance&gt;0.0&lt;/consolBalance&gt;
      &lt;consolDepositBalance&gt;0.0&lt;/consolDepositBalance&gt;
      &lt;consolOverdueBalance&gt;0.0&lt;/consolOverdueBalance&gt;
      &lt;consolUnbilledOrders&gt;76.8&lt;/consolUnbilledOrders&gt;
      &lt;creditHoldOverride/&gt;
      &lt;customFieldList&gt;
          &lt;customField/&gt;
      &lt;/customFieldList&gt;
      &lt;dateCreated&gt;2011-06-26T12:30:00+05:30&lt;/dateCreated&gt;
      &lt;defaultAddress&gt;Anderson Boughton Inc.&amp;lt;br&amp;gt;1488 Main&amp;lt;br&amp;gt;Apt 113&amp;lt;br&amp;gt;Seattle WA 98106&amp;lt;br&amp;gt;US&lt;/defaultAddress&gt;
      &lt;displaySymbol&gt;$&lt;/displaySymbol&gt;
      &lt;email&gt;boughton751@cscatering.com&lt;/email&gt;
      &lt;emailPreference/&gt;
      &lt;emailTransactions&gt;false&lt;/emailTransactions&gt;
      &lt;entityId&gt;Anderson Boughton Inc.&lt;/entityId&gt;
      &lt;entityStatus&gt;
          &lt;name&gt;CUSTOMER-Closed Won&lt;/name&gt;
          &lt;internalId&gt;13&lt;/internalId&gt;
      &lt;/entityStatus&gt;
      &lt;faxTransactions&gt;false&lt;/faxTransactions&gt;
      &lt;firstVisit&gt;2012-07-12T01:30:49+05:30&lt;/firstVisit&gt;
      &lt;giveAccess&gt;false&lt;/giveAccess&gt;
      &lt;globalSubscriptionStatus/&gt;
      &lt;internalId&gt;75&lt;/internalId&gt;
      &lt;isBudgetApproved&gt;false&lt;/isBudgetApproved&gt;
      &lt;isInactive&gt;false&lt;/isInactive&gt;
      &lt;isPerson&gt;false&lt;/isPerson&gt;
      &lt;lastModifiedDate&gt;2012-12-19T11:50:14+05:30&lt;/lastModifiedDate&gt;
      &lt;lastPageVisited&gt;HP xw4100&lt;/lastPageVisited&gt;
      &lt;lastVisit&gt;2012-07-12T01:30:49+05:30&lt;/lastVisit&gt;
      &lt;leadSource&gt;
          &lt;name&gt;Partner Referral&lt;/name&gt;
          &lt;internalId&gt;99993&lt;/internalId&gt;
      &lt;/leadSource&gt;
      &lt;overrideCurrencyFormat&gt;false&lt;/overrideCurrencyFormat&gt;
      &lt;partner&gt;
          &lt;name&gt;Online electronics&lt;/name&gt;
          &lt;internalId&gt;171&lt;/internalId&gt;
      &lt;/partner&gt;
      &lt;phone&gt;206-555-1302&lt;/phone&gt;
      &lt;priceLevel&gt;
          &lt;name&gt;Base Price&lt;/name&gt;
          &lt;internalId&gt;1&lt;/internalId&gt;
      &lt;/priceLevel&gt;
      &lt;printTransactions&gt;false&lt;/printTransactions&gt;
      &lt;receivablesAccount&gt;
          &lt;name&gt;Use System Preference&lt;/name&gt;
          &lt;internalId&gt;-10&lt;/internalId&gt;
      &lt;/receivablesAccount&gt;
      &lt;salesRep&gt;
          &lt;name&gt;A Wolfe&lt;/name&gt;
          &lt;internalId&gt;-5&lt;/internalId&gt;
      &lt;/salesRep&gt;
      &lt;shipComplete&gt;false&lt;/shipComplete&gt;
      &lt;stage/&gt;
      &lt;symbolPlacement/&gt;
      &lt;taxable&gt;false&lt;/taxable&gt;
      &lt;unbilledOrders&gt;76.8&lt;/unbilledOrders&gt;
      &lt;webLead&gt;No&lt;/webLead&gt;
  &lt;/customer&gt;
  &lt;/Customers&gt;
  </code></pre>
  
  <p>So i have nested structure for <code>&lt;accessRole&gt;</code> which i want to flatten out like 
  <code>&lt;accessRole-name&gt;</code>and i don't want to display element like <code>&lt;internalId&gt;</code>.</p>
  
  <p>Please find a code snippet of my model:</p>
  
  <pre><code>try {
               FileWriter fileWriter = new FileWriter ("D:\\adapter-framework\\Customer_XML.xml");
               JAXBContext jaxbContext = JAXBContext.newInstance(extractedRecordsArray[0].getClass());
               Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
               fileWriter.append("&lt;Customers&gt;");
               fileWriter.append('\n');
               for(int i = 0; i &lt; extractedRecordsArray.length - 761 ; i++)
               {          
                  jaxbMarshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
                  jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                  //jaxbMarshaller.marshal(extractedRecordsArray[i],fileWriter);
                  jaxbMarshaller.marshal(extractedRecordsArray[i],System.out);
                  fileWriter.append('\n');
                  AdapterLogger.debug(this.getClass().getName(), "Extracted record number : " + i);
               }        
              fileWriter.append("&lt;/Customers&gt;");
              fileWriter.close();
            } catch (JAXBException e) {
              e.printStackTrace();
             }
  </code></pre>
  
  <p>Please help me out if someone knows about it.</p>
  
  <p>Thanks.</p>