Page 1 of 1

sample code for creating /customXml/item1.xml through coding

PostPosted: Thu Nov 25, 2010 5:48 pm
by Indhu
Hi Jason,
Can you please give me a sample coding for creating /customXml/item1.xml through coding?

I tried to create using createDocxWithCustomXml.java as given in docx4j.2.6.0 version. since it returns null document in createCustomXmlDocument method, there is no customXML found in the document. I’ve attached the document.

I tried to return a document in createCustomXmlDocument method using following code
public static Document createCustomXmlDocument(Document document)
{
Element root = document.createElement("root");
root.setAttribute("att1", "att1val");
root.setTextContent("some value");

return document;
}

But it returns null pointer exception. The return type Document is of type org.w3c.dom.Document, since customXmlDataStorage.setDocument() supports either org.w3c.dom.Document or InputStream. I tried with org.w3c.dom.Document

As I’m working with a project, I need to complete this urgently.

Pls do favor. please the see the attached document below. it doesn contain any injected cuxtomXml.

Re: sample code for creating /customXml/item1.xml through coding

PostPosted: Thu Nov 25, 2010 6:13 pm
by jason
That sample does say:

Code: Select all
   public static org.w3c.dom.Document createCustomXmlDocument() {
      
      // TODO: implement
      
      return null;      
   }


The intent is that you create the org.w3c.dom.Document, however you like. Maybe that should be clearer.

How you do that is a general Java + XML question. Any of the top hits when you google "java create dom document" will tell you how to do it.

For convenience though, docx4j's XmlUtils contains:

Code: Select all
   /** Use DocumentBuilderFactory to create and return a new w3c dom Document. */
   public static org.w3c.dom.Document neww3cDomDocument()


Gentle suggestion: if you are expecting urgent help (over and above what you have also already had via email), you should be paying for support :-)