A
ab2305
this is my method (followed by exception):
public void generateXML(String fileName, BookInfoBean bookInfo){
try{
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance( );
DocumentBuilder parser = factory.newDocumentBuilder( );
Document doc = parser.newDocument();
Node root = doc.createElement(AmazonConstants.BOOKINFO);
doc.appendChild(root);
Node asin = doc.createElement(AmazonConstants.ASIN);
root.appendChild(asin);
asin.appendChild(doc.createTextNode(bookInfo.getAsin()));
Node title= doc.createElement(AmazonConstants.TITLE);
root.appendChild(title);
title.appendChild(doc.createTextNode(bookInfo.getTitle()));
Node rank= doc.createElement(AmazonConstants.SALESRANK);
root.appendChild(rank);
rank.appendChild(doc.createTextNode(bookInfo.getSalesRank()));
//create/save the actual file.
final Transformer
transformer=TransformerFactory.newInstance().newTransformer();
final DocumentType doctype = doc.getDoctype();
if (doctype != null)
{
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
doctype.getPublicId());
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype.getSystemId());
}
transformer.transform(new DOMSource(doc),new
StreamResult(new FileOutputStream(fileName)));
} catch (Exception ex) {
System.err.println(ex.getClass( ));
System.err.println(ex.getMessage( ));
ex.printStackTrace();
}
---------------------exception
ERROR: ''
class javax.xml.transform.TransformerException
java.lang.NullPointerException
javax.xml.transform.TransformerException:
java.lang.NullPointerException
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)
Caused by: java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
... 4 more
---------
java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)
public void generateXML(String fileName, BookInfoBean bookInfo){
try{
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance( );
DocumentBuilder parser = factory.newDocumentBuilder( );
Document doc = parser.newDocument();
Node root = doc.createElement(AmazonConstants.BOOKINFO);
doc.appendChild(root);
Node asin = doc.createElement(AmazonConstants.ASIN);
root.appendChild(asin);
asin.appendChild(doc.createTextNode(bookInfo.getAsin()));
Node title= doc.createElement(AmazonConstants.TITLE);
root.appendChild(title);
title.appendChild(doc.createTextNode(bookInfo.getTitle()));
Node rank= doc.createElement(AmazonConstants.SALESRANK);
root.appendChild(rank);
rank.appendChild(doc.createTextNode(bookInfo.getSalesRank()));
//create/save the actual file.
final Transformer
transformer=TransformerFactory.newInstance().newTransformer();
final DocumentType doctype = doc.getDoctype();
if (doctype != null)
{
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
doctype.getPublicId());
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype.getSystemId());
}
transformer.transform(new DOMSource(doc),new
StreamResult(new FileOutputStream(fileName)));
} catch (Exception ex) {
System.err.println(ex.getClass( ));
System.err.println(ex.getMessage( ));
ex.printStackTrace();
}
---------------------exception
ERROR: ''
class javax.xml.transform.TransformerException
java.lang.NullPointerException
javax.xml.transform.TransformerException:
java.lang.NullPointerException
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)
Caused by: java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
... 4 more
---------
java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)