When using the XmlUtils.unmarshalString(), if I don't provide the schema in the parent tag(i.e. xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"), then I get an exception below:
org.xml.sax.SAXParseException: The prefix "w" for element "w:r" is not bound.
Below is a snippet of my code that I'm using currently. Notice how I have to add the schema to my <w:r> tag for it to work.
- Code: Select all
private static final String MAIN_SCHEMA = "xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"";
...
public static P getPageBreak(){
org.docx4j.wml.P paragraph = f.createP();
paragraph.getParagraphContent().add(XmlUtils.unmarshalString("<w:r " + MAIN_SCHEMA + "><w:br w:type=\"page\" /></w:r>"));
return paragraph;
}
Not a big deal, just wondering if there's a better way than always adding in a reference to the schema to the XML.
Thanks,
Justin