Page 1 of 1

how to marshal CTOMath

PostPosted: Sat Nov 07, 2015 7:30 pm
by yufeng0528
hi all.
my goal is transfrom omml to mathml. and i do a lot of search, get the steps below:
1:get the math Dom, and to Node
2:use Transformer to mathml by OMML2MML.XSL
But I stunk in the first step.

this is my code. It throw exception in line 2:JAXBContext.newInstance.
could anyone tell me how to fix , or other ways to my goal.
thanks in andvance
Code: Select all
                        CTOMath ctoMath = (CTOMath)((JAXBElement) o).getValue();
                        JAXBContext context = JAXBContext.newInstance(CTOMath.class, ObjectFactory.class, org.docx4j.wml.ObjectFactory.class);               
                       
                        DOMResult res = new DOMResult();
                       
                        Marshaller marshaller = context.createMarshaller();
                        marshaller.marshal(ctoMath, res);
                       
                       
                       System.out.println(res.getNode().getNodeName());
                       
                        Transformer transformer = TransformerFactory.newInstance().newTransformer(new javax.xml.transform.stream.StreamSource("/Users/trymore/Downloads/OMML2MML.XSL"));

                       
                        DOMSource ds = new DOMSource(res.getNode());
                        StringWriter writer = new StringWriter();
                        StreamResult sr = new StreamResult(writer);

                        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                        //convert ooml to mathml
                        transformer.transform(ds,sr);

                        String mmlString=writer.toString();


Code: Select all
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {http://schemas.microsoft.com/office/word/2012/wordml}dataBinding.
   this problem is related to the following location:
      at protected java.util.List org.docx4j.wml.SdtPr.rPrOrAliasOrLock
      at org.docx4j.wml.SdtPr
      at protected org.docx4j.wml.SdtPr org.docx4j.wml.SdtBlock.sdtPr
      at org.docx4j.wml.SdtBlock
      at protected java.util.List org.docx4j.wml.Comments$Comment.content
      at org.docx4j.wml.Comments$Comment
      at protected java.util.List org.docx4j.wml.Comments.comment
      at org.docx4j.wml.Comments
      at public org.docx4j.wml.Comments org.docx4j.wml.ObjectFactory.createComments()
      at org.docx4j.wml.ObjectFactory
      at protected java.util.List org.docx4j.wml.CTRPrChange$RPr.egrPrBase
      at org.docx4j.wml.CTRPrChange$RPr
      at protected org.docx4j.wml.CTRPrChange$RPr org.docx4j.wml.CTRPrChange.rPr
      at org.docx4j.wml.CTRPrChange
      at protected org.docx4j.wml.CTRPrChange org.docx4j.wml.RPrAbstract.rPrChange
      at org.docx4j.wml.RPr
      at protected org.docx4j.wml.RPr org.docx4j.math.CTCtrlPr.rPr
      at org.docx4j.math.CTCtrlPr
      at protected org.docx4j.math.CTCtrlPr org.docx4j.math.CTFPr.ctrlPr
      at org.docx4j.math.CTFPr
      at protected org.docx4j.math.CTFPr org.docx4j.math.CTF.fPr
      at org.docx4j.math.CTF
      at public org.docx4j.math.CTF org.docx4j.math.ObjectFactory.createCTF()
      at org.docx4j.math.ObjectFactory
      at protected java.util.List org.docx4j.math.CTOMath.egoMathElements
      at org.docx4j.math.CTOMath

Re: how to marshal CTOMath

PostPosted: Tue Nov 10, 2015 1:41 pm
by yufeng0528
ok,i have resolved.
Code: Select all
JAXBContext context = documentPart.getJAXBContext();//JAXBContext.newInstance(CTOMath.class, ObjectFactory.class, org.docx4j.wml.ObjectFactory.class);
                        ObjectFactory mathFactory = new ObjectFactory();
                       
//                        System.out.println(XmlUtils.marshaltoString(mathFactory.createOMath(ctoMath), context));
                       
                        System.out.println(XmlUtils.marshaltoString(mathFactory.createOMath(ctoMath)));
                       
                        DOMResult res = new DOMResult();
                       
                        Marshaller marshaller = context.createMarshaller();
                        marshaller.marshal(mathFactory.createOMath(ctoMath), res);

Re: how to marshal CTOMath

PostPosted: Wed Nov 11, 2015 8:04 am
by jason
Sorry for the delay in replying; I've been busy with customers...

See https://github.com/plutext/docx4j/blob/ ... mulae.java for a worked example.