/** Bind the content controls of the passed document to the xml. */ public static void bind(WordprocessingMLPackage wmlPackage, String xmlDocument, int flags) throws Docx4JException { ByteArrayInputStream xmlStream = null; if (flags == FLAG_NONE) { // do everything flags = (FLAG_BIND_INSERT_XML | FLAG_BIND_BIND_XML | FLAG_BIND_REMOVE_SDT | FLAG_BIND_REMOVE_XML); } if ((flags & FLAG_BIND_INSERT_XML) == FLAG_BIND_INSERT_XML) { try { xmlStream = new ByteArrayInputStream(xmlDocument.getBytes("UTF-8")); } catch (UnsupportedEncodingException e1) { xmlStream = new ByteArrayInputStream(xmlDocument.getBytes()); } } bind(wmlPackage, xmlStream, flags); }
/** Bind the content controls of the passed document to the xml. */ public static void bind(WordprocessingMLPackage wmlPackage, InputStream xmlDocument, int flags) throws Docx4JException { if (flags == FLAG_NONE) { // do everything flags = (FLAG_BIND_INSERT_XML | FLAG_BIND_BIND_XML | FLAG_BIND_REMOVE_SDT | FLAG_BIND_REMOVE_XML); } Document xmlDoc = null; if ((flags & FLAG_BIND_INSERT_XML) == FLAG_BIND_INSERT_XML) { DocumentBuilder documentBuilder = null; try { documentBuilder = XmlUtils.getDocumentBuilderFactory().newDocumentBuilder(); xmlDoc = documentBuilder.parse(xmlDocument); } catch (Exception e) { throw new Docx4JException( "Problems creating a org.w3c.dom.Document for the passed input stream.", e); } } bind(wmlPackage, xmlDoc, flags); }