Exception loading .docx XML
Posted: Sat Mar 06, 2010 11:20 pm
Hi,
I have a .docx XML (Customer.xml) which contains the MS Word tags with content, when i try to load the XML using docx4j API . I am getting the following exception :-
org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't load xml from D:\Sample\Employee.xml
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:173)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:163)
at PDFGenerator.main(PDFGenerator.java:17)
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"document"). Expected elements are <{http://schemas.microsoft.com/office/2006/xmlPackage}package>,<{http://schemas.microsoft.com/office/2006/xmlPackage}xmlData>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:616)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
Here is my java code:-
String inputFilePath = System.getProperty("user.dir")+ "/Customer.xml";
try {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File(inputFilePath));
wordMLPackage.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
wordMLPackage);
((org.docx4j.convert.out.pdf.viaXSLFO.Conversion) c)
.setSaveFO(new java.io.File(
ApplicationConstants.XML_FILE_PATH + ".fo"));
OutputStream os = new java.io.FileOutputStream(
ApplicationConstants.XML_FILE_PATH + ".pdf");
c.output(os);
Is there any thing i am doing wrong here, Why i am unable to load the XML? I have also JARS in place. Please correct the code if needed and shed some light into it.
Thanks,
Rithu
I have a .docx XML (Customer.xml) which contains the MS Word tags with content, when i try to load the XML using docx4j API . I am getting the following exception :-
org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't load xml from D:\Sample\Employee.xml
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:173)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:163)
at PDFGenerator.main(PDFGenerator.java:17)
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"document"). Expected elements are <{http://schemas.microsoft.com/office/2006/xmlPackage}package>,<{http://schemas.microsoft.com/office/2006/xmlPackage}xmlData>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:616)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
Here is my java code:-
String inputFilePath = System.getProperty("user.dir")+ "/Customer.xml";
try {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File(inputFilePath));
wordMLPackage.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
wordMLPackage);
((org.docx4j.convert.out.pdf.viaXSLFO.Conversion) c)
.setSaveFO(new java.io.File(
ApplicationConstants.XML_FILE_PATH + ".fo"));
OutputStream os = new java.io.FileOutputStream(
ApplicationConstants.XML_FILE_PATH + ".pdf");
c.output(os);
Is there any thing i am doing wrong here, Why i am unable to load the XML? I have also JARS in place. Please correct the code if needed and shed some light into it.
Thanks,
Rithu