title: docx4j - delete wml P element
body: <p>I'm using docx4j to work with a Microsoft Word template. I want to know how to either remove or hide a P element in the template. I'm able to traverse the code to get a specific P element, now I need to know how to remove or hide that P element. Can anyone help? I get all the P elements using the following code:</p>
  
  <pre><code>private static List&lt;Object&gt; getAllElementFromObject(Object obj, Class&lt;?&gt; toSearch) {
  
      List&lt;Object&gt; result = new ArrayList&lt;Object&gt;();
      if (obj instanceof JAXBElement) obj = ((JAXBElement&lt;?&gt;) obj).getValue();
  
      if (obj.getClass().equals(toSearch))
          result.add(obj); 
      else if (obj instanceof ContentAccessor) {
          List&lt;?&gt; children = ((ContentAccessor) obj).getContent();
          for (Object child : children) {
              result.addAll(getAllElementFromObject(child, toSearch));
          }
      }
      return result; 
  }
  
  private void replaceTextValue_P(WordprocessingMLPackage template ) throws Exception{        
  
      List&lt;Object&gt; texts = getAllElementFromObject(template.getMainDocumentPart(), P.class);
  
      // List&lt;Object&gt; pCon = new ArrayList&lt;Object&gt;();
  
      for (Object text : texts) {         
          P textElement = (P) text;
          template.getMainDocumentPart().getContent().remove(textElement); // DOES NOT WORK!
  
        writeDocxToStream(template, "C:\\Temp\\Target.docx");
  }
  }
  
  private void writeDocxToStream(WordprocessingMLPackage template, String target) throws IOException, Docx4JException {
  
      File f = new File(target);
      template.save(f);
  }
  </code></pre>