Page 1 of 1

Master document / Sub document (continue...)

PostPosted: Thu Jul 21, 2011 9:16 pm
by Tony_Bird
Hi,

I want to create un master document in which the sub documents are inserted like "references". That's an example from Office Open XML documentation (http://www.ecma-international.org/news/TC45_current_work/Office%20Open%20XML%20Part%201%20-%20Fundamentals.pdf) :

Example: Consider a master document, whose three subdocuments are called Start, Middle, and End, respectively. Master’s Main Document part has a corresponding relationships part that contains the following, in which Start.docx, Middle.docx, and End.docx are packages containing the corresponding subdocuments:

Code: Select all
<Relationships xmlns="…">
  <Relationship Id="rId5"Type="http://…/subDocument" Target="Start.docx" TargetMode="External"/>
  <Relationship 1 Id="rId6" Type="http://…/SubDocument" Target="Middle.docx" TargetMode="External"/>
  <Relationship Id="rId7" Type="http://…/SubDocument" Target="End.docx" TargetMode="External"/>
</Relationships>

The master document’s Main Document part contains subDoc elements that reference its subdocuments:

Code: Select all
<w:document xmlns:r="…" xmlns:wx="…" …>
  <w:body>
    <w:p …>
      <w:pPr>
       …
      </w:pPr>
    </w:p>
    <w:subDoc r:id="rId5"/>
     …
    <w:subDoc r:id="rId6"/>
     …
    <w:subDoc r:id="rId7"/>
    …
  </w:body>
</w:document>

end example


I want to use docx4j package to do that. But I did find the "subdocument" class in the package. Has anyone an idea where I can find this class? Otherwise, how to use others class in docx4j to creat un <w:subDoc> objet?

Thanks

Re: Master document / Sub document

PostPosted: Thu Jul 21, 2011 10:11 pm
by jason
org.docx4j.wml.ObjectFactory contains:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link CTRel }{@code >}}
     *
     */

    @XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "subDoc", scope = P.class)
    public JAXBElement<CTRel> createPSubDoc(CTRel value) {
        return new JAXBElement<CTRel>(_PSubDoc_QNAME, CTRel.class, P.class, value);
    }

 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4

Re: Master document / Sub document

PostPosted: Thu Jul 21, 2011 10:26 pm
by Tony_Bird
Get it. Thank you Jason!
I would notice the "P" in front of "SubDoc".

Re: Master document / Sub document

PostPosted: Fri Jul 22, 2011 12:15 am
by Tony_Bird
The second question: somebody can show me how to use it?

Re: Master document / Sub document (continue...)

PostPosted: Fri Jul 22, 2011 10:37 pm
by jason
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting

                org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();             
                // OR
                // org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
               
                CTRel rel = factory.createCTRel();
                rel.setId("relId3"); // or whatever    
            JAXBElement<CTRel> subDoc = factory.createPSubDoc(rel);
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4

Re: Master document / Sub document (continue...)

PostPosted: Sat Jul 23, 2011 2:02 am
by Tony_Bird
Dear Jason,

Following the code sample, I’ll add one line to add the sub doc object to the main part of the master document :

Code: Select all
wordMLPackage.getMainDocumentPart().addObject(subDoc);


But I didn’t catch how to add sub documents references to the master document.

Code: Select all
<Relationship Id="rId7" Type="http://…/SubDocument" Target="End.docx" TargetMode="External"/>


I notice that the class org.docx4j.relationships.Relationship contains the members and functions that permit to set the values of Type, Target and TargetMode. But the class org.docx4j.wml.CTRel has not the members like Type, Target and TargetMode.

Could you give me more specification?

Thanks

Re: Master document / Sub document (continue...)

PostPosted: Sat Jul 23, 2011 9:17 pm
by jason
Hi, a subdoc is an external part, like a hyperlink.

See http://dev.plutext.org/trac/docx4j/changeset/1630 for a new example

cheers .. Jason

Re: Master document / Sub document (continue...)

PostPosted: Tue Jul 26, 2011 8:00 pm
by Tony_Bird
Thanks Jason!