Thanks for the quick resposne - im getting some errors when trying to run this code however.
Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 142; The element type "w:r" must be terminated by the matching end-tag "</w:r>".]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:354)
at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:334)
at com.reed.america.Main.main(Main.java:23)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 142; The element type "w:r" must be terminated by the matching end-tag "</w:r>".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
... 7 more
I define this string and try adding it to my document
- Code: Select all
String openXML = "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
+ "<w:pPr>"
+ "<w:jc w:val=\"center\"/>"
+ "<w:rPr>"
+ "<w:u w:val=\"single\"/>"
+ "<w:lang w:val=\"en-AU\"/>"
+"</w:rPr>"
+"</w:pPr>"
+ "<w:r>"
+ "<w:rPr>"
+ "<w:u w:val=\"single\"/>"
+ "<w:lang w:val=\"en-AU\"/>"
+"</w:rPr>"
+ "<w:t>Underlined and centred</w:t>"
+"</w:r>"
+"</w:p>";
wordMLPackage.getMainDocumentPart().addObject(
org.docx4j.XmlUtils.unmarshalString(openXML));
but no luck :'(