we cannot pass slidePart.getJaxbElement() to the marshaltoW3CDomDocument method, whilst, this is possible for documentPart.getJaxbElement().
This is because, marshaltoW3CDomDocument internally calls javax.xml.bind.Marshaller.marshall, which expects a jaxb context. Check the below code snippet.
- Code: Select all
Parts parts = pMlPackage.getParts();
Map<PartName,Part> allPartsMap = parts.getParts();
SlidePart slidePart = (SlidePart)allPartsMap.get(partName);
Sld sld = slidePart.getJaxbElement();
org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument(sld);
It will throw the below exception as Sld doesn't come in the class hierarchy..
- Code: Select all
java.lang.RuntimeException: javax.xml.bind.JAXBException: class org.pptx4j.pml.Sld nor any of its super class is known to this context.
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:539)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:517)
at com.ne.PPTXHandler.main(PPTXHandler.java:30)
Caused by: javax.xml.bind.JAXBException: class org.pptx4j.pml.Sld nor any of its super class is known to this context.
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:535)
... 2 more
Whereas, for document, it will work fine without any exception, as MainDocumentPart extends DocumentPart<org.docx4j.wml.Document>.
- Code: Select all
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
XmlUtils.marshaltoW3CDomDocument(documentPart.getJaxbElement());
docx4j and pptx4j APIs must be consistent.