when i test below code ,an exception java.lang.NoClassDefFoundError: com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper occur.
- Code: Select all
import java.io.File;
import java.util.List;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.wml.Body;
public class RemoveParagraph
{
public static void main(String[] args) throws Exception {
String inputfilepath = "C://workspace//D.docx";
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
.getJaxbElement();
Body body = wmlDocumentEl.getBody();
String xpath1="//w:p[w:r[w:t[contains(text(),'Tag1')]]]|//w:p[w:r[w:t[contains(text(),'Tag1')]]]/following-sibling::node()[count(.|//w:p[w:r[w:t[contains(text(),'Tag11')]]]/preceding-sibling::node())=count(//w:p[w:r[w:t[contains(text(),'Tag11')]]]/preceding-sibling::node())] |//w:p[w:r[w:t[contains(text(),'Tag11')]]]";
List<Object> list = documentPart.getJAXBNodesViaXPath(xpath1, false);
for(int i=0;i<list.size();i++)
{
org.docx4j.wml.P p = (org.docx4j.wml.P) list.get(i);
body.getContent().remove(p);
}
wordMLPackage.save(new File("c:\\workspace\\dd_out.docx"));
}
}
my operating environment is jdk1.5、jaxb-2_1_9、docx4j-2-7.jar...attachment is my test document.
when i remove the table of the test document,the exception will not occur,but i insert a table into the test document,the exception occur.
thanks in advance!
tosswang