</country>
</countries>
</root>
*/
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
// System.out.println(
// XmlUtils.marshaltoString(
// wordMLPackage.getMainDocumentPart().getJaxbElement(), true) );
// Process conditionals and repeats
OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
odh.preprocess();
// Since the JAXB binding stuff seems to remember
// old artifacts, we'll first create a 'clean' object here
// from something we've marshalled to.
org.w3c.dom.Document xmlNode = XmlUtils.marshaltoW3CDomDocument(
wordMLPackage.getMainDocumentPart().getJaxbElement());
Binder<Node> binder = Context.jc.createBinder();
Object jaxbElement = (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
// Test (1)
// After processing, we should have 3 tables
List<Object> list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
"//w:tbl", false );
int count = list.size();
assertTrue("expected 3 tables but got " + count, count==3 );
// First table has 2 rows
list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
"/descendant::w:tbl[1]/*[local-name()='sdt' or local-name()='tr']" , false );
// for (Object o : list){
// System.out.println(XmlUtils.marshaltoString(o, true));
// }
count = list.size();
assertTrue("expected 2 rows but got " + count, count==2 );
// Second table has 3 rows
list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
"/descendant::w:tbl[2]/*[local-name()='sdt' or local-name()='tr']" , false );
count = list.size();
assertTrue("expected 3 rows but got " + count, count==3 );
// Third table has 4 rows
list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
"/descendant::w:tbl[3]/*[local-name()='sdt' or local-name()='tr']" , false );
count = list.size();
assertTrue("expected 4 rows but got " + count, count==4 );
// Apply the bindings
AtomicInteger bookmarkId = odh.getNextBookmarkId();
BindingHandler bh = new BindingHandler(wordMLPackage);
bh.setStartingIdForNewBookmarks(bookmarkId);
bh.applyBindings(wordMLPackage.getMainDocumentPart());
// create a 'clean' object again ..
xmlNode = XmlUtils.marshaltoW3CDomDocument(
wordMLPackage.getMainDocumentPart().getJaxbElement());
binder = Context.jc.createBinder();
jaxbElement = (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
// Test (3)
// Test that the last w:tc in the last table contains 'P c3 r3'