Thank you for creating the docx4j library as an open source project to help us all - I really appreciate the hard work that you must have put in over the years.
I am trying to get upto speed on docx4j and I went through the example "FromVariableReplacement.java" at https://github.com/plutext/docx4j/blob/ ... ement.java - I am able to run this example successfully.
Question:
This code takes text of the form ${foo} and then
- converts it into a content control
- injects a question with text 'foo'
- injects an answer with text 'foo'
- injects the correct Xpath to make the binding work.
Problem:
I want to do the same thing in the example, but with a simple bind (ie no questions or conditionals). How do I accomplish this using this example?
I went through the "createParts" method in AbstractMigrator:
- Code: Select all
protected void createParts(WordprocessingMLPackage pkgOut) throws Exception {
// Add OpenDoPE parts to target
// .. conditions - not that we use this here
ConditionsPart conditionsPart = new ConditionsPart(new PartName("/customXml/item1.xml")); // name doesn't matter
pkgOut.getMainDocumentPart().addTargetPart(conditionsPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS); // Word will silently drop the CXPs if they aren't added to the MDP!
addPropertiesPart(conditionsPart, "http://opendope.org/conditions");
conditionsPart.setJaxbElement(new Conditions());
// .. XPaths
xPathsPart = new XPathsPart(new PartName("/customXml/item1.xml"));
pkgOut.getMainDocumentPart().addTargetPart(xPathsPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
addPropertiesPart(xPathsPart, "http://opendope.org/xpaths");
xPathsPart.setJaxbElement(new Xpaths());
// .. Questions
questionsPart = new QuestionsPart(new PartName("/customXml/item1.xml"));
pkgOut.getMainDocumentPart().addTargetPart(questionsPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
addPropertiesPart(questionsPart,"http://opendope.org/questions");
questionsPart.setJaxbElement(new Questionnaire());
Questionnaire.Questions questions = new Questionnaire.Questions();
questionsPart.getJaxbElement().setQuestions(questions);
// .. Standardised Answer format
standardisedAnswersPart = new StandardisedAnswersPart(new PartName("/customXml/item1.xml"));
pkgOut.getMainDocumentPart().addTargetPart(standardisedAnswersPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
storeItemID = addPropertiesPart(standardisedAnswersPart, "http://opendope.org/answers");
standardisedAnswersPart.setJaxbElement(new Answers());
}
Unfortunately I am facing a roadblock here. I've created an instance of ComponentsPart to hold the custom XML and modified the code as shown below:
- Code: Select all
protected ComponentsPart componentsPart;
// snipped for brevity
componentsPart = new ComponentsPart(new PartName(("/customXml/item1.xml")));
pkgOut.getMainDocumentPart().addTargetPart(componentsPart,RelationshipsPart.AddPartBehaviour.RENAME_IF_NAME_EXISTS);
addPropertiesPart(componentsPart,"http://opendope.org/answers"); // TODO what namespace should I use here?
What is the namespace that I should use for the Components Part? ( Link: https://github.com/plutext/docx4j/blob/ ... sPart.java )
The "addPropertiesPart" method requires a namespace for this? if so what is the namespace parameter that I should supply for simple XML binding.
There is already a list of XML namespaces for the other components.
- Questions: http://opendope.org/questions
Answers: http://opendope.org/answers
XPaths: http://opendope.org/xpaths
What is the namespace that I should use for simple XML inserts? I want to insert something like:
- Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<employees>
<employee>
<name>Karina Leal</name>
<hireDate>1999-04-01</hireDate>
<title>Manager</title>
</employee>
</employees>
and then have it bound via Xpath.