Page 1 of 1

cannot open the generated file

PostPosted: Wed Nov 23, 2011 6:52 am
by adi
Hi Jason

I have some problem by processing a word document which already has a customXml/item1.xml
I can open the doc one first time, read all content controls in it, create a new item2.xml with some data and save it.
When I try to open the generated doc with Winword it says "Document cannot be open, because the content has some problems". but i go next and than I can open it.
Then I try to do the same with the generated document, open and process content controls, but this time i have this Exception:

[18:52:51] [DEBUG] [Part] [setPackage]: setPackage called for org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[18:52:51] [DEBUG] [LoadFromZipNG] [addPartsFromRelationships]:
For Relationship Id=rId1 Source is /customXml/item1.xml, Target is itemProps1.xml, type: http://schemas.openxmlformats.org/offic ... omXmlProps
[18:52:51] [DEBUG] [LoadFromZipNG] [getRawPart]: resolved uri: customXml/itemProps1.xml
java.io.IOException: part 'customXml/itemProps1.xml' not found
at org.docx4j.openpackaging.io.LoadFromZipNG.getInputStreamFromZippedPart(LoadFromZipNG.java:308)
at org.docx4j.openpackaging.io.LoadFromZipNG.getRawPart(LoadFromZipNG.java:513)
at org.docx4j.openpackaging.io.LoadFromZipNG.getPart(LoadFromZipNG.java:427)
at org.docx4j.openpackaging.io.LoadFromZipNG.addPartsFromRelationships(LoadFromZipNG.java:350)
at org.docx4j.openpackaging.io.LoadFromZipNG.getPart(LoadFromZipNG.java:449)
at org.docx4j.openpackaging.io.LoadFromZipNG.addPartsFromRelationships(LoadFromZipNG.java:350)
at org.docx4j.openpackaging.io.LoadFromZipNG.getPart(LoadFromZipNG.java:449)
at org.docx4j.openpackaging.io.LoadFromZipNG.addPartsFromRelationships(LoadFromZipNG.java:350)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:243)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:225)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:177)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at LoadFoo.loadFoo(LoadFoo.java:69)
at LoadFoo.main(LoadFoo.java:58)
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.LoadFromZipNG.addPartsFromRelationships(LoadFromZipNG.java:352)


Do you have any idea why or if I'm doing something wrong?

in attach you have the doc and the program with which i test it.

thanks
Adrian

Re: cannot open the generated file

PostPosted: Fri Dec 09, 2011 2:31 pm
by jason
Hi Adrian

Sorry for the long delay; I only noticed this post just now!

Your Foo.docx only contains a single custom xml part (item1.xml which contains officeDocument/2006/bibliography), and nothing for data binding (no custom xml part, and none of the content controls contain a data binding property). Perhaps this docx is what resulted from saving in Word after it said it had problems with the content and you clicked next? Or perhaps you never set up any data bindings in it at all?

Can you post your original docx?

cheers .. Jason

Re: cannot open the generated file

PostPosted: Sat Dec 10, 2011 6:00 am
by adi
Hi Jason

thank you for the response
I found where the problem is, it happens when I try to add a new customXmlDataStoragePart in Foo.docx.
My Foo.docx already contains a customStoragePart (item1.xml) with his CustomXmlDataStoragePropertiesPart (itemProps1.xml).
I then try to add a second one (item2.xml)...but for the PropsPart I used the :

CustomXmlDataStoragePropertiesPart part = new CustomXmlDataStoragePropertiesPart();

giving no Name for PropsPart as parameter in the constructor.

But the default constructor of CustomXmlDataStoragePropertiesPart beeing this one:
public CustomXmlDataStoragePropertiesPart() throws InvalidFormatException {
super(new PartName("/customXML/itemProps1.xml"));
init();
}


as you can see, I got the same PropsPart (itemProps1.xml) for the second customStoragePart (item2.xml).

My solution was to use the other constructor :
public CustomXmlDataStoragePropertiesPart(PartName partName) throws InvalidFormatException {
super(partName);
init();
}


I created the new name of PropsPart with this Method
(I was inspired from your code on public CustomXmlDataStoragePart(Parts parts) )

private static PartName getPartNamePropPart (Parts parts) throws InvalidFormatException {

PartName partName = null;
int partNum = 1;
if (parts!=null) {
while (parts.get(new PartName("/customXml/itemProps" + partNum + ".xml"))!=null) {
partNum++;
}
}
partName = new PartName("/customXml/itemProps" + partNum + ".xml");

return partName;
}


Now I'm having for every customPart this own PropsPart and so not having problems anymore.
item1.xml - > itemProps1.xml
item2.xml - > itemProps2.xml
itemN.xml - > itemPropsN.xml

thank you
Adrian