Page 1 of 1

generat custom Xml part: Couldn't locate part by storeItemId

PostPosted: Wed Jul 20, 2011 5:15 am
by adi
Hi Jason

I have again a problem by generating customXml when I use your CustomXmlBinding (changed it a bit).
In BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()); the JaxbElement wont be marshaled...

The dom document will be null here
org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument(part.getJaxbElement() );

and in the logs i see :
[16:23:01] [ERROR] [BindingHandler] [xpathGetString]: Couldn't locate part by storeItemId {6517eaad-b242-4cf0-a49d-4a6c3f31c6e1}

This seems to be better without BindingHandler.applyBinding() but in this case I have the "Click to add" text in a document and I want to get rid of those...
There are some Documents which I can't open in Word if I activate BindingHandler.applyBinding().

I'm attaching my version of CustomXmlBinding.
Could you please check this out ?

Thanks
Adrian

Re: How to generate the custom Xml part in Java?

PostPosted: Wed Jul 20, 2011 10:06 am
by jason
Hi Adrian

You'll need to provide C:\Projects\AVAM\officeXML\CustomXml.xml in order for your code to run.

cheers .. Jason

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Wed Jul 20, 2011 6:40 pm
by adi
Hi Jason

This will be dynamically generated like this:

CustomXmlDataStoragePart customXmlDataStoragePart = new CustomXmlDataStoragePart(parts);
String[] contentControlsStrings = readContentControls(parent);
CustomXmlDataStorage data = new CustomXmlDataStorageImpl();
data.setDocument(createCustomXmlDocument(contentControlsStrings));
customXmlDataStoragePart.setData(data);
parent.addTargetPart(customXmlDataStoragePart);

and looks like the attach...
Or am I missing something?

thanks
Adrian

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Wed Jul 20, 2011 11:24 pm
by jason
Yes, I see that now I look. I'd gotten a stack trace, and wasn't minded to examine your code at that point..

Code: Select all
javax.xml.transform.TransformerException: java.io.FileNotFoundException: C:\Projects\AVAM\officeXML\CustomXml.xml (The system cannot find the path specified)
   at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:297)
   at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:330)
   at CustomXmlBindingTest.createCustomXmlDocument(CustomXmlBindingTest.java:172)
   at CustomXmlBindingTest.injectCustomXmlDataStoragePart(CustomXmlBindingTest.java:125)
   at CustomXmlBindingTest.main(CustomXmlBindingTest.java:61)


Anyway,

and in the logs i see :
[16:23:01] [ERROR] [BindingHandler] [xpathGetString]: Couldn't locate part by storeItemId {6517eaad-b242-4cf0-a49d-4a6c3f31c6e1}


To fix this, after

Code: Select all
      CustomXmlDataStoragePart customXmlDataStoragePart = injectCustomXmlDataStoragePart(wordMLPackage.getMainDocumentPart(),
            wordMLPackage.getParts());
      
      String dataBindingStoreItemId = addProperties(customXmlDataStoragePart);


add:

Code: Select all
      wordMLPackage.getCustomXmlDataStorageParts().put(dataBindingStoreItemId.toLowerCase(),
            customXmlDataStoragePart );      


If there are any remaining issues, please advise. (Documents you can't open in Word??)

cheers .. Jason

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Thu Jul 21, 2011 1:13 am
by adi
Hi Jason

Thank you for your fix, it's OK now.

I did embed the "CustomXmlBinding" in our Web-App and generated documents from there as OutputStream to have an Download with "Save as" Window.

Code: Select all
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
saver.save(oStream);   
return oStream;


In attach you have two docs which I generated with the same program and one of them can't open in Word...
I both cases I didn't see any Exceptions...

regards
Adrian

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Thu Jul 21, 2011 10:15 am
by jason
Regarding problematic documents, there are 2 cases:

1- docx created outside docx4j (eg in Word or something else eg OpenOffice). If docx4j can't open one of these, or roundtrips it incorrectly, I'd want to investigate this as a high priority. Historically, this has been rare.

2- you use docx4j to create an invalid docx (or one Word can't open). There is nothing to stop you doing this; this is generally your problem unless you can show that docx4j is doing something wrong, or you can narrow the problem down to a particular structure and ask a specific question about how to deal with it.

Often, case 2 is painful, because Word may give you no clue as to what is wrong.

In this case, Word is helpful. It says the problem is at column 41586 in document.xml. Looking there, it is immediately preceded by:-

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
      <w:tr w:rsidTr="005A53AB" w:rsidR="00DA4589" w:rsidRPr="00DC4D8E">
        <w:trPr>
          <w:trHeight w:val="419"/>
        </w:trPr>
        <w:sdt>
          <w:sdtPr>
            <w:rPr>
              <w:rStyle w:val="Arial1000Zchn"/>
            </w:rPr>
            <w:alias w:val="cc0050COL1"/>
            <w:tag w:val="cc0050COL1"/>
            <w:id w:val="7180960"/>
            <w:showingPlcHdr/>
            <w:text w:multiLine="true"/>
            <w:dataBinding w:storeItemID="{e85a7f07-fe34-4e7b-a383-30392ff86cf5}" w:xpath="/root/cc0050COL1"/>
          </w:sdtPr>
          <w:sdtContent/>
        </w:sdt>
        <w:sdt>
          <w:sdtPr>
            <w:rPr>
              <w:rStyle w:val="Arial1000Zchn"/>
            </w:rPr>
            <w:alias w:val="cc0050COL2"/>
            <w:tag w:val="cc0050COL2"/>
            <w:id w:val="7180964"/>
            <w:showingPlcHdr/>
            <w:text w:multiLine="true"/>
            <w:dataBinding w:storeItemID="{e85a7f07-fe34-4e7b-a383-30392ff86cf5}" w:xpath="/root/cc0050COL2"/>
          </w:sdtPr>
          <w:sdtContent/>
        </w:sdt>
        <w:sdt>
          <w:sdtPr>
            <w:rPr>
              <w:rStyle w:val="Arial1000Zchn"/>
            </w:rPr>
            <w:alias w:val="cc0050COL3"/>
            <w:tag w:val="cc0050COL3"/>
            <w:id w:val="7180968"/>
            <w:showingPlcHdr/>
            <w:text w:multiLine="true"/>
            <w:dataBinding w:storeItemID="{e85a7f07-fe34-4e7b-a383-30392ff86cf5}" w:xpath="/root/cc0050COL3"/>
          </w:sdtPr>
          <w:sdtContent/>
        </w:sdt>
      </w:tr>
 
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


So you have a table row which contains empty <w:sdtContent/> elements, rather than <w:tc>.

Word is a bit particular about the content of w:tc, and w:tr by the looks of it.

I guess the question is whether the docx4j binding handler should be protecting you in this case or not. Possibly/probably, since we handle somewhat similar cases eg in OpenDoPE handler iirc.

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Fri Jul 22, 2011 2:13 am
by adi
Hi Jason

I don't understand why sometimes after applying binding I get an empty <w:sdtContent/> element and sometime this one

Code: Select all
<w:sdtContent>
                  <w:tc>
                     <w:tcPr>
                        <w:tcW w:w="3240" w:type="dxa" />
                        <w:gridSpan w:val="3" />
                        <w:tcBorders>
                           <w:left w:val="single" w:color="auto" w:sz="4" w:space="0" />
                           <w:bottom w:val="single" w:color="auto" w:sz="4"
                              w:space="0" />
                           <w:right w:val="single" w:color="auto" w:sz="4"
                              w:space="0" />
                        </w:tcBorders>
                     </w:tcPr>
                     <w:p>
                        <w:pPr>
                           <w:tabs>
                              <w:tab w:val="left" w:pos="2977" />
                           </w:tabs>
                           <w:overflowPunct w:val="false" />
                           <w:autoSpaceDE w:val="false" />
                           <w:autoSpaceDN w:val="false" />
                           <w:adjustRightInd w:val="false" />
                           <w:spacing w:before="40" w:line="220" w:lineRule="atLeast" />
                           <w:textAlignment w:val="baseline" />
                           <w:rPr>
                              <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
                              <w:sz w:val="20" />
                              <w:szCs w:val="20" />
                              <w:lang w:val="de-DE" />
                           </w:rPr>
                        </w:pPr>
                     </w:p>
                  </w:tc>
               </w:sdtContent>


Both contains nothing to display...why did they generate different if the related element in CustomXml.xml was the same ( <cc0050COL3 /> )

The original before binding applying was in both cases :

Code: Select all
<w:sdtContent>
                  <w:tc>
                     <w:tcPr>
                        <w:tcW w:w="3240" w:type="dxa" />
                        <w:gridSpan w:val="3" />
                        <w:tcBorders>
                           <w:left w:val="single" w:sz="4" w:space="0" w:color="auto" />
                           <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto" />
                           <w:right w:val="single" w:sz="4" w:space="0" w:color="auto" />
                        </w:tcBorders>
                     </w:tcPr>
                     <w:p w:rsidR="00DA4589" w:rsidRPr="00DC4D8E" w:rsidRDefault="001A0CB9"
                        w:rsidP="00EB0F34">
                        <w:pPr>
                           <w:tabs>
                              <w:tab w:val="left" w:pos="2977" />
                           </w:tabs>
                           <w:overflowPunct w:val="0" />
                           <w:autoSpaceDE w:val="0" />
                           <w:autoSpaceDN w:val="0" />
                           <w:adjustRightInd w:val="0" />
                           <w:spacing w:before="40" w:line="220" w:lineRule="atLeast" />
                           <w:textAlignment w:val="baseline" />
                           <w:rPr>
                              <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
                              <w:sz w:val="20" />
                              <w:szCs w:val="20" />
                              <w:lang w:val="de-DE" />
                           </w:rPr>
                        </w:pPr>
                        <w:r w:rsidRPr="008346D5">
                           <w:rPr>
                              <w:rStyle w:val="Platzhaltertext" />
                           </w:rPr>
                           <w:t>Click to add.</w:t>
                        </w:r>
                     </w:p>
                  </w:tc>
               </w:sdtContent>


I only can't open the document in word if <w:sdtContent/> element is empty (without <w:tc>) ...

thanks
Adrian

Re: generat custom Xml part: Couldn't locate part by storeIt

PostPosted: Fri Jul 22, 2011 10:45 pm
by jason
I'd be very surprised if you got different results on different runs with identical content.

What is the sdtPr?