Page 1 of 1

Separation of openpackaging and XML

PostPosted: Sat Oct 08, 2011 1:29 pm
by Jim
Hello,

After some time away from this project (and BTW I have gotten very good reviews from the first iteration), I'm trying to add more features to my pptx4j tool. I am starting with a PPTx as a template and using pptx4j to make custom and/or user-driven updates on the fly, generating a new PPTx.

At the moment, I'm concentrating on adding and replacing images, since I failed in getting this to work in version 1. I am trying to add a Pic, its Image, and their Relationship to the document. My current problem is that the Image is not showing up. I have noticed that my Image does not have Compression set. (not sure if that is the cause or not, but...) I have found that setCompression is only available on the XML side, not the openpackaging side.

I went back to the docs, and it recommends reading in a pptx with the openpackaging PresentationMLPackage class. I suppose that is why I did it that way to begin with. Are the openpackaging and XML classes completely separate? i.e., if I start with this openpackaging class, am I able to "cross over" and use XML classes too?

Or am I so far out in the weeds that my question doesn't even make sense? (I have also wondered if I should be reading in my template and creating a totally new object, rather than trying to update the template object itself).

Any advice would be appreciated.

Thanks,
Jim

Re: Separation of openpackaging and XML

PostPosted: Sat Oct 08, 2011 2:04 pm
by jason
Hi Jim

You have a tree of "parts" - this is represented at the openpackaging level. (The package is essentially a container for this tree of parts)

In terms of the spec, each part is an XML document. In docx4j/pptx4j each part object contains a JAXBElement, which is an object representation of the XML.

You are free to populate that JAXBElement however you wish.. when you open an existing pptx, the parts are read and each JAXBElement populated automatically.

When you add a part (eg adding a slide), you are responsible for setting the JAXBElement.

So generally you work with the JAXBElement object tree. But sometimes it makes sense to marshall to a string or a W3C XML DOM element, and manipulate that, then unmarshall again. Similarly, sometimes then easiest way to create the JAXBElement object tree is to unmarshall from XML represented as a string or DOM or SAX or whatever.

The same principles apply whether you are opening an existing pptx, or creating a new one from scratch. Things should work equally well either way.

I'll add a sample for adding an image to a slide. Stay tuned ...

cheers .. Jason

Re: Separation of openpackaging and XML

PostPosted: Mon Oct 10, 2011 2:40 pm
by Jim
Thanks, Jason--I am eagerly awaiting your example, so I can do this the proper way.

Jim

Re: Separation of openpackaging and XML

PostPosted: Mon Oct 10, 2011 11:52 pm
by jason
See the separate thread "HOWTO insert picture" :-)