title: Docx4J is not replacing placeholders
body: <p>I am trying to replace a simple 'Place Holder<code>in MS Word 2007 using</code>Docx4J<code>. I created the placeholder by</code>Reference > Insert Citation > Add New Placeholder` </p>
  
  <p>Below is my Docx4J code</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  import javax.xml.bind.JAXBElement;
  import org.docx4j.openpackaging.exceptions.Docx4JException;
  import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
  import org.docx4j.wml.ContentAccessor;
  import org.docx4j.wml.Text;
  
  /*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  /**
   *
   * @author Yohan
   */
  public class Main {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          // TODO code application logic here
          new Main();
      }
      public Main()
      {
          try
          {
              WordprocessingMLPackage template = getTemplate("C:/Users/Yohan/Desktop/Yohan.docx");
              replacePlaceholder(template,"Plane","Placeholder1");
              writeDocxToStream(template,"C:/Users/Yohan/Desktop/Yohan2.docx");
  
              System.out.println("Operation Completed");
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  
  
  
      private WordprocessingMLPackage getTemplate(String name) throws Docx4JException, FileNotFoundException {
          WordprocessingMLPackage template = WordprocessingMLPackage.load(new FileInputStream(new File(name)));
          return template;
      }
  
          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 replacePlaceholder(WordprocessingMLPackage template, String name, String placeholder ) {
          List&lt;Object&gt; texts = getAllElementFromObject(template.getMainDocumentPart(), Text.class);
  
          for (Object text : texts) {
              Text textElement = (Text) text;
              if (textElement.getValue().equals(placeholder)) {
                  textElement.setValue(name);
              }
          }
      }
  
  
  
      private void writeDocxToStream(WordprocessingMLPackage template, String target) throws IOException, Docx4JException {
          File f = new File(target);
          template.save(f);
      }
  
  }
  </code></pre>
  
  <p>This generated the below in Netbeans console.</p>
  
  <pre><code>[main] INFO org.docx4j.jaxb.Context - java.vendor=Oracle Corporation
  [main] INFO org.docx4j.jaxb.Context - java.version=1.8.0_05
  [main] INFO org.docx4j.jaxb.Context - No MOXy JAXB config found; assume not intended..
  [main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
  [main] INFO org.docx4j.jaxb.Context - Using Java 6/7 JAXB implementation
  [main] INFO org.docx4j.jaxb.Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
  [main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
  [main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
  [main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
  [main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
  [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - Detected WordProcessingML package 
  [main] INFO org.docx4j.openpackaging.io3.Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
  [main] INFO org.docx4j.utils.XPathFactoryUtil - xpath implementation: org.apache.xpath.jaxp.XPathFactoryImpl
  [main] INFO org.docx4j.openpackaging.io.Load - Found a CustomXmlPart, named /customXml/item1.xml
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /customXml/itemProps1.xml
  [main] INFO org.docx4j.openpackaging.io.Load - Identified/registered ds:itemId {2da45ade-e2fe-4251-9c73-a623aa57ebb0}
  [main] INFO org.docx4j.openpackaging.io3.Load3 - package read;  elapsed time: 10932 ms
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/document.xml
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart, unmarshall via binder
  [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
  [main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.BibliographyPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.CustomXmlDataStoragePropertiesPart
  [main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
  Operation Completed
  </code></pre>
  
  <p>However in Yohan2.docx, nothing is changed, it is a pure copy of Yohan.docx. What have I done wrong here?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tested the MERGEFIELD example from the GITHUB but it also didn't work. Below is the output printed in console</p>
  
  <pre><code>[main] INFO org.docx4j.jaxb.Context - java.vendor=Oracle Corporation
  [main] INFO org.docx4j.jaxb.Context - java.version=1.8.0_05
  [main] INFO org.docx4j.jaxb.Context - No MOXy JAXB config found; assume not intended..
  [main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
  [main] INFO org.docx4j.jaxb.Context - Using Java 6/7 JAXB implementation
  [main] INFO org.docx4j.jaxb.Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
  [main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
  [main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
  [main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
  [main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
  [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - Detected WordProcessingML package 
  [main] INFO org.docx4j.openpackaging.io3.Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
  [main] INFO org.docx4j.utils.XPathFactoryUtil - xpath implementation: org.apache.xpath.jaxp.XPathFactoryImpl
  [main] WARN org.docx4j.openpackaging.contenttype.ContentTypeManager - DefaultPart used for part '/word/stylesWithEffects.xml' of content type 'application/vnd.ms-word.stylesWithEffects+xml'
  [main] INFO org.docx4j.openpackaging.io3.Load3 - package read;  elapsed time: 14766 ms
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/document.xml
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart, unmarshall via binder
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Found 9 fields 
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KunDenName'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KUNDENNAME'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenstrasse'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yourdate'
  [main] INFO org.docx4j.model.fields.DateFormatInferencer - Infering dates based using International formats
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yournumber'
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/settings.xml
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart, unmarshall via binder
  [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
  [main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart
  [main] WARN org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart - 
  [main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Found 9 fields 
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenname'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KunDenName'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KUNDENNAME'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenstrasse'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yourdate'
  [main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yournumber'
  [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
  [main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart
  [main] WARN org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart - 
  [main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
  </code></pre>