I am trying to read a Word-Document from a .xml file. The .xml file was saved by Microsoft Word 2010, 'Save as Word XML-Document (*.xml)'.
Here is my code:
- Code: Select all
String docx= "/report_templates/MyDoc.xml";
JAXBContext jc = Context.jcXmlPackage;
Unmarshaller u = jc.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
InputStream iStream = getClass().getResourceAsStream(docx);
org.docx4j.xmlPackage.Package wmlPackageEl = (org.docx4j.xmlPackage.Package)((JAXBElement)u.unmarshal(new javax.xml.transform.stream.StreamSource(iStream))).getValue();
org.docx4j.convert.in.FlatOpcXmlImporter xmlPackage = new org.docx4j.convert.in.FlatOpcXmlImporter( wmlPackageEl);
WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage)xmlPackage.get();
This is the error I am getting:
- Code: Select all
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.convert.in.FlatOpcXmlImporter.addPartsFromRelationships(FlatOpcXmlImporter.java:258)
at org.docx4j.convert.in.FlatOpcXmlImporter.get(FlatOpcXmlImporter.java:183)
at com.bmw.eap.common.report.docx.DocxCreator.generateBoardAgenda(DocxCreator.java:136)
at com.bmw.eap.web.commands.SearchBoardDateAdministrationCmd.exportAgendaWord(SearchBoardDateAdministrationCmd.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Truncated. see log file for complete stacktrace
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to getPart
at org.docx4j.convert.in.FlatOpcXmlImporter.getRawPart(FlatOpcXmlImporter.java:604)
at org.docx4j.convert.in.FlatOpcXmlImporter.getRawPart(FlatOpcXmlImporter.java:387)
at org.docx4j.convert.in.FlatOpcXmlImporter.getPart(FlatOpcXmlImporter.java:326)
at org.docx4j.convert.in.FlatOpcXmlImporter.addPartsFromRelationships(FlatOpcXmlImporter.java:256)
at org.docx4j.convert.in.FlatOpcXmlImporter.get(FlatOpcXmlImporter.java:183)
Truncated. see log file for complete stacktrace
java.lang.IllegalArgumentException: prefix dcterms is not bound to a namespace
at com.sun.xml.bind.DatatypeConverterImpl._parseQName(DatatypeConverterImpl.java:324)
at com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.parseXsiType(XsiTypeLoader.java:52)
at com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.startElement(XsiTypeLoader.java:30)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:369)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:347)
Truncated. see log file for complete stacktrace
In my xml this is the part where dcterms occurs:
- Code: Select all
<pkg:part pkg:name="/docProps/core.xml" pkg:contentType="application/vnd.openxmlformats-package.core-properties+xml" pkg:padding="256">
<pkg:xmlData>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:creator>Matthias</dc:creator>
<cp:lastModifiedBy>Matthias</cp:lastModifiedBy>
<cp:revision>2</cp:revision>
<dcterms:created xsi:type="dcterms:W3CDTF">2012-01-27T15:44:00Z</dcterms:created>
<dcterms:modified xsi:type="dcterms:W3CDTF">2012-01-27T15:44:00Z</dcterms:modified>
</cp:coreProperties>
</pkg:xmlData>
</pkg:part>
I couldn't find anybody else having this problem in the forum... so I am wondering what I am doing wrong.
Thanks in advance,
Matthias