title: Java how to get rid of redundant code
body: <p>In Java I parse a XML document. This XML is a Purchase Order and from this XML I create a PO document in our ERP-system.</p>
  
  <p>I use domparser to parse the XML.
  So eventually I have code like this:</p>
  
  <pre><code>--this is an excerpt --
      //ShipTo
      Element shipToElement = CXMLHandlerObj.getChildElement(elementOrderRequestHeader, "ShipTo");
  
      //Address
      Element shipToAddressElement = CXMLHandlerObj.getChildElement(shipToElement, "Address");
          /*get attributes of Address*/
          notesHandlerObj.docOrder.replaceItemValue("ShipToParty_addressID", shipToAddressElement.getAttribute("addressID"));
          notesHandlerObj.docOrder.replaceItemValue("ShipToParty_addressIDDomain", shipToAddressElement.getAttribute("addressIDDomain"));
          notesHandlerObj.docOrder.replaceItemValue("ShipToParty_isoCountryCode", shipToAddressElement.getAttribute("isoCountryCode"));
  </code></pre>
  
  <p>But the XML also contains at the top a OrderRequestHeader which has a type attribute in it:</p>
  
  <pre><code>    &lt;OrderRequestHeader orderDate="2017-04-04T12:00:00+00:00" orderID="4550144777" orderType="regular" orderVersion="1" type="new"&gt;
  </code></pre>
  
  <p>Below this element all the details of the order are found.</p>
  
  <p>The "type" attribute can have values like :  New or Update.
  The type will be "new" if the PO XML is send for the first time and the type will be "update" if the same PO is sent but then with an update contained within it. 
  Note that the XML structure is the same but only the type is different.
  When the type is "New", I will just parse the XML and create the PO document. But if the type is "Update" then I want to check every element and update the document and mail the changes accordingly..</p>
  
  <p>Now the problem is that for the parsing of the XML I need to create a new PO or update an existing one. This I can do by the following ways:</p>
  
  <p><strong>1. creating two methods :</strong></p>
  
  <pre><code> 1. create new PO
   2. update PO
  </code></pre>
  
  <p>In the create method I can parse the xml and add values from element to the document.</p>
  
  <p>In the update method I can parse again all elements but also check which data has been changed.</p>
  
  <p><strong>2. I can put a if and else statement before every element</strong></p>
  
  <p>The methods of above are a bit redudant is there any simpler way of doing this? </p>