Page 1 of 1

Use of XmlUtils.unmarshalString()

PostPosted: Tue Aug 04, 2009 10:29 pm
by jbeltran

When using the XmlUtils.unmarshalString(), if I don't provide the schema in the parent tag(i.e. xmlns:w=""), 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=\"\"";
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.