CTTextField goes inside CTTextParagraph
From the XML shown further below, docx4j webapp generates:
Method 1: via ObjectFactory
Using java Syntax Highlighting
import java.lang.Long;
import org.docx4j.dml.CTTextCharacterProperties;
import org.docx4j.dml.CTTextField;
import org.docx4j.dml.CTTextParagraph;
public class Foo
{
public CTTextParagraph createIt
() {
org.
docx4j.
dml.
ObjectFactory dmlObjectFactory
= new org.
docx4j.
dml.
ObjectFactory();
CTTextParagraph textparagraph
= dmlObjectFactory.
createCTTextParagraph();
// Create object for endParaRPr
CTTextField textfield
= dmlObjectFactory.
createCTTextField();
textparagraph.
getEGTextRun().
add( textfield
);
// Create object for rPr
CTTextCharacterProperties textcharacterproperties
= dmlObjectFactory.
createCTTextCharacterProperties();
textfield.
setRPr(textcharacterproperties
);
textcharacterproperties.
setLang( "en-AU");
textcharacterproperties.
setSmtId( new Long(0
) );
textfield.
setT( "1");
textfield.
setId( "{54DA7E74-E873-4E88-B918-E260C39D583F}");
textfield.
setType( "slidenum");
// Create object for endParaRPr
CTTextCharacterProperties textcharacterproperties2
= dmlObjectFactory.
createCTTextCharacterProperties();
textparagraph.
setEndParaRPr(textcharacterproperties2
);
textcharacterproperties2.
setLang( "en-US");
textcharacterproperties2.
setSmtId( new Long(0
) );
return textparagraph
;
}
}
Parsed in 0.017 seconds, using
GeSHi 1.0.8.4
Method 2
Using java Syntax Highlighting
String openXML
= "<a:p xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
+ "<a:fld id=\"{54DA7E74-E873-4E88-B918-E260C39D583F}\" type=\"slidenum\">"
+ "<a:rPr lang=\"en-AU\"/>"
+ "<a:t>1</a:t>"
+ "</a:fld>"
+ "<a:endParaRPr dirty=\"false\" lang=\"en-US\"/>"
+ "</a:p>";
CTTextParagraph textparagraph
= (CTTextParagraph
)XmlUtils.
unmarshalString(openXML
);
Parsed in 0.015 seconds, using
GeSHi 1.0.8.4