Hello
I have a XML DB. I write the first element. I can not get the entries to (fragments) to
write to the Database. I know I do not have the error handler setup right. The error
stops the process on the transform. Is there some debugging techniques I could use
to understand why the fragments are not being appended. All the data is collected and in place. Thanks.
java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(ToUnknownStream.java:342)
[code]
dom:
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import model.notes.reference.ReadXML;
import org.w3c.dom.*;
[/code]
[code]
XML DB
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE links [<!ELEMENT links (link)+><!ELEMENT link (linkName,linkPath,linkDesc,entryName,dbName,dbHome,entryFrame,entryTab,entryDesc,isEntryDir,isEntryFile,frameHome,tabHome,fileName,tabSelectedIndex,isFileTask,isTabTask,isFrameTask,dow,date,time,key)><!ATTLIST link action CDATA #REQUIRED><!ELEMENT linkName (#PCDATA)><!ELEMENT linkPath (#PCDATA)><!ELEMENT linkDesc (#PCDATA)><!ELEMENT entryName (#PCDATA)><!ELEMENT dbName (#PCDATA)><!ELEMENT dbHome (#PCDATA)><!ELEMENT entryFrame (#PCDATA)><!ELEMENT entryTab (#PCDATA)><!ELEMENT entryDesc (#PCDATA)><!ELEMENT isEntryDir (#PCDATA)><!ELEMENT isEntryFile (#PCDATA)><!ELEMENT frameHome (#PCDATA)><!ELEMENT tabHome (#PCDATA)><!ELEMENT fileName (#PCDATA)><!ELEMENT tabSelectedIndex (#PCDATA)><!ELEMENT isFileTask (#PCDATA)><!ELEMENT isTabTask (#PCDATA)><!ELEMENT isFrameTask (#PCDATA)><!ELEMENT dow (#PCDATA)><!ELEMENT date (#PCDATA)><!ELEMENT time (#PCDATA)><!ELEMENT key (#PCDATA)>]>
<links>
<link action="meta">
<linkName>system</linkName>
<linkPath>C:\Users\Steves\.targetGuide\admin_\admin\Note Folder\bookmarkDB</linkPath>
<linkDesc>system</linkDesc>
<entryName>system</entryName>
<dbName>system</dbName>
<dbHome>system</dbHome>
<entryFrame>system</entryFrame>
<entryTab>system</entryTab>
<entryDesc>system</entryDesc>
<isEntryDir>system</isEntryDir>
<isEntryFile>system</isEntryFile>
<frameHome>system</frameHome>
<tabHome>system</tabHome>
<fileName>system</fileName>
<tabSelectedIndex>system</tabSelectedIndex>
<isFileTask>system</isFileTask>
<isTabTask>system</isTabTask>
<isFrameTask>system</isFrameTask>
<dow>system</dow>
<date>system</date>
<time>system</time>
<key>system</key>
</link>
</links>
[/code]
[code]
error:
ERROR: ''
ERROR: ''
Feb 11, 2013 8:00:19 AM model.bookMark.BookMarkActions$4 run
SEVERE: null
javax.xml.transform.TransformerException: java.lang.NullPointerException
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:720)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:317)
at model.bookMark.WriteBookMarks.append(WriteBookMarks.java:443)
at model.bookMark.ConnectBookMarkDAO.writeNewBookMark(ConnectBookMarkDAO.java:469)
at model.bookMark.BookMarkActions$4.run(BookMarkActions.java:368)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(ToUnknownStream.java:342)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:244)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:136)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:665)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:711)
... 18 more
---------
java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(ToUnknownStream.java:342)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:244)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:136)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:665)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:711)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:317)
at model.bookMark.WriteBookMarks.append(WriteBookMarks.java:443)
at model.bookMark.ConnectBookMarkDAO.writeNewBookMark(ConnectBookMarkDAO.java:469)
at model.bookMark.BookMarkActions$4.run(BookMarkActions.java:368)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
[/code]
[code]
ReadXML.java
ublic Document readXML(String aSystemDir) {
String M =(": in public Document readXML("+aSystemDir+") var: (String aSystemDir):\n");
System.out.println(M);
try {
String systemDir = aSystemDir;
//File f = new File(systemDir);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ReadXMLErrorHandler(System.err));
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setValidating(true);
dbf.setFeature("http://xml.org/sax/features/validation", true);
db = null;
db = dbf.newDocumentBuilder();
//System.out.println("doc=null");
doc = db.parse(new InputSource(systemDir));
docType = doc.getDoctype();
setDocType(docType);
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
xmlString = result.getWriter().toString();
setXmlString(xmlString);
System.out.println(xmlString);
setDocType(docType);
setDoc(doc);
//Element de = doc.getDocumentElement();
root = doc.getDocumentElement();
setRoot(root);
rootName = root.getNodeName();
setRootName(rootName);
//@misc:
System.out.println(C + M + AND + rootName + ": rootName:\n");
//@misc:
System.out.println(C + M + AND + root + ": root = doc.getDocumentElement();:\n");
//@misc:
System.out.println(C + M + AND + docType + ": docType=doc.getDoctype();:\n");
// ModelUtils.outputDom(doc);
} catch (SAXException ex) {
Logger.getLogger(ReadXML.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ReadXML.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(ReadXML.class.getName()).log(Level.SEVERE, null, ex);
}
return doc;
}
[/code]
[code]
write:
public void append(String systemDir, String action) throws TransformerConfigurationException, TransformerException, ParserConfigurationException, SAXException, IOException {
String M = ": in public void append(" + systemDir + c + action + ") var: String systemDir,String action<-- \n";
System.out.println(M);
ReadXML read = new ReadXML();
doc = read.readXML(systemDir);
setDoc(doc);
docType = doc.getDoctype();
setDocType(docType);
root = (Element) doc.getDocumentElement();
setRoot(root);
setDoc(doc);
addFragment(doc);//doc, linkName, linkPath, linkDesc, action
//////////////////
//Output the XML
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
xmlString = result.getWriter().toString();
setXmlString(xmlString);
System.out.println(xmlString);
//print xml
setDoc(doc);
System.out.println("Here's the the original Document : It does nest the new link \n\n" + xmlString);
sysOut(systemDir);
writeAppend(systemDir, action);
}
private void writeAppend(String systemDir, String action) {
String M = (": in private void writeAppend(" + systemDir + c + action + ") var: (String systemDir,String action):\n");
System.out.println(M);
setAction(action);
try {
OutputStream fout = new FileOutputStream(systemDir);
OutputStream bout = new BufferedOutputStream(fout);
OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");
out.write(xmlDeclaration);
out.write("<!DOCTYPE links [");
out.write("<!ELEMENT links (link)+>");
out.write("<!ELEMENT link (linkName,linkPath,linkDesc,entryName,dbName,dbHome,entryFrame,entryTab,entryDesc,isEntryDir,isEntryFile,frameHome,tabHome,fileName,tabSelectedIndex,isFileTask,isTabTask,isFrameTask,dow,date,time,key)>");
out.write("<!ATTLIST link action CDATA #REQUIRED>");
out.write("<!ELEMENT linkName (#PCDATA)>");
out.write("<!ELEMENT linkPath (#PCDATA)>");
out.write("<!ELEMENT linkDesc (#PCDATA)>");
out.write("<!ELEMENT entryName (#PCDATA)>");
out.write("<!ELEMENT dbName (#PCDATA)>");
out.write("<!ELEMENT dbHome (#PCDATA)>");
out.write("<!ELEMENT entryFrame (#PCDATA)>");
out.write("<!ELEMENT entryTab (#PCDATA)>");
out.write("<!ELEMENT entryDesc (#PCDATA)>");
out.write("<!ELEMENT isEntryDir (#PCDATA)>");
out.write("<!ELEMENT isEntryFile (#PCDATA)>");
out.write("<!ELEMENT frameHome (#PCDATA)>");
out.write("<!ELEMENT tabHome (#PCDATA)>");
out.write("<!ELEMENT fileName (#PCDATA)>");
out.write("<!ELEMENT tabSelectedIndex (#PCDATA)>");
out.write("<!ELEMENT isFileTask (#PCDATA)>");
out.write("<!ELEMENT isTabTask (#PCDATA)>");
out.write("<!ELEMENT isFrameTask (#PCDATA)>");
out.write("<!ELEMENT dow (#PCDATA)>");
out.write("<!ELEMENT date (#PCDATA)>");
out.write("<!ELEMENT time (#PCDATA)>");
out.write("<!ELEMENT key (#PCDATA)>");
out.write("]>");
out.write(xmlString);
out.flush(); //Don't forget to flush!
out.close();
//@misc:
System.out.println(xmlString + " xmlString \n");
out.flush();
out.close();
} catch (UnsupportedEncodingException e) {
System.out.println("This VM does not support the Latin-1 character set.");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
private void addFragment(Document doc) {
String M = (": in public void setupXML(" +doc.getXmlVersion()+ ") var: (Document doc, ):\n");
System.out.println(M);
Element link;
root = doc.getDocumentElement();
DocumentFragment fragment = doc.createDocumentFragment();
link = makeLinkNode();
fragment.appendChild(link);
root.appendChild(fragment);
setDoc(doc);
}
private Element makeLinkNode() {
String M = (": in private Element makeLinkNode() var: (:\n");
System.out.println(M);
Element nameNode = doc.createElement(linkNameElement);
Text nameTextNode = doc.createTextNode(linkName);
nameNode.appendChild(nameTextNode);
Element urlNode = doc.createElement(linkPathElement);
Text urlTextNode = doc.createTextNode(linkPath);
urlNode.appendChild(urlTextNode);
Element descNode = doc.createElement(linkDescElement);
Text descTextNode = doc.createTextNode(linkDesc);
descNode.appendChild(descTextNode);
Element entryNameNode = doc.createElement(entryNameElement);
Text entryNameTextNode = doc.createTextNode(entryName);
entryNameNode.appendChild(entryNameTextNode);
Element dbNameNode = doc.createElement(dbNameElement);
Text dbNameTextNode = doc.createTextNode(dbName);
dbNameNode.appendChild(dbNameTextNode);
Element dbHomeNode = doc.createElement(dbHomeElement);
Text dbHomeTextNode = doc.createTextNode(dbHome);
dbHomeNode.appendChild(dbHomeTextNode);
Element entryFrameNode = doc.createElement(entryFrameElement);
Text entryFrameTextNode = doc.createTextNode(entryFrame);
entryFrameNode.appendChild(entryFrameTextNode);
Element entryTabNode = doc.createElement(entryTabElement);
Text entryTabTextNode = doc.createTextNode(entryTab);
entryTabNode.appendChild(entryTabTextNode);
Element entryDescNode = doc.createElement(entryDescElement);
Text entryDescTextNode = doc.createTextNode(entryDesc);
entryDescNode.appendChild(entryDescTextNode);
Element isEntryDirNode = doc.createElement(isEntryDirElement);
Text isEntryDirTextNode = doc.createTextNode(isEntryDir);
isEntryDirNode.appendChild(isEntryDirTextNode);
Element isEntryFileNode = doc.createElement(isEntryFileElement);
Text isEntryFileTextNode = doc.createTextNode(isEntryFile);
isEntryFileNode.appendChild(isEntryFileTextNode);
Element frameHomeNode = doc.createElement(frameHomeElement);
Text frameHomeTextNode = doc.createTextNode(frameHome);
frameHomeNode.appendChild(frameHomeTextNode);
Element tabHomeNode = doc.createElement(tabHomeElement);
Text tabHomeTextNode = doc.createTextNode(tabHome);
tabHomeNode.appendChild(tabHomeTextNode);
Element fileNameNode = doc.createElement(fileNameElement);
Text fileNameTextNode = doc.createTextNode(fileName);
fileNameNode.appendChild(fileNameTextNode);
Element tabSelectedIndexNode = doc.createElement(tabSelectedIndexElement);
Text tabSelectedIndexTextNode = doc.createTextNode(tabSelectedIndex);
tabSelectedIndexNode.appendChild(tabSelectedIndexTextNode);
Element isFileTaskNode = doc.createElement(isFileTaskElement);
Text isFileTaskTextNode = doc.createTextNode(isFileTask);
isFileTaskNode.appendChild(isFileTaskTextNode);
Element isTabTaskNode = doc.createElement(isTabTaskElement);
Text isTabTaskTextNode = doc.createTextNode(isTabTask);
isTabTaskNode.appendChild(isTabTaskTextNode);
Element isFrameTaskNode = doc.createElement(isFrameTaskElement);
Text isFrameTaskTextNode = doc.createTextNode(isFrameTask);
isFrameTaskNode.appendChild(isFrameTaskTextNode);
Element dowNode = doc.createElement(dowElement);
Text dowTextNode = doc.createTextNode(dow);
dowNode.appendChild(dowTextNode);
Element dateNode = doc.createElement(dateElement);
Text dateTextNode = doc.createTextNode(date);
dateNode.appendChild(dateTextNode);
Element timeNode = doc.createElement(timeElement);
Text timeTextNode = doc.createTextNode(time);
timeNode.appendChild(timeTextNode);
Element keyNode = doc.createElement(keyElement);
Text keyTextNode = doc.createTextNode(key);
keyNode.appendChild(keyTextNode);
Element linkNode = doc.createElement(linkElement);
linkNode.setAttribute("action", action);
linkNode.appendChild(nameNode);
linkNode.appendChild(urlNode);
linkNode.appendChild(descNode);
linkNode.appendChild(entryNameNode);
linkNode.appendChild(dbNameNode);
linkNode.appendChild(dbHomeNode);
linkNode.appendChild(entryFrameNode);
linkNode.appendChild(entryTabNode);
linkNode.appendChild(entryDescNode);
linkNode.appendChild(isEntryDirNode);
linkNode.appendChild(isEntryFileNode);
linkNode.appendChild(frameHomeNode);
linkNode.appendChild(tabHomeNode);
linkNode.appendChild(fileNameNode);
linkNode.appendChild(tabSelectedIndexNode);
linkNode.appendChild(isFileTaskNode);
linkNode.appendChild(isTabTaskNode);
linkNode.appendChild(isFrameTaskNode);
linkNode.appendChild(dowNode);
linkNode.appendChild(dateNode);
linkNode.appendChild(timeNode);
linkNode.appendChild(keyNode);
return (linkNode);
}
[/code]
[code]
output bean:
<!ELEMENT link (linkName,linkPath,linkDesc,entryName,dbName,dbHome,entryFrame,entryTab,entryDesc,isEntryDir,isEntryFile,frameHome,tabHome,fileName,tabSelectedIndex,isFileTask,isTabTask,isFrameTask,dow,date,time,key)>
<!ATTLIST link action CDATA #REQUIRED>
<!ELEMENT linkName (#PCDATA)>
<!ELEMENT linkPath (#PCDATA)>
<!ELEMENT linkDesc (#PCDATA)>
<!ELEMENT entryName (#PCDATA)>
<!ELEMENT dbName (#PCDATA)>
<!ELEMENT dbHome (#PCDATA)>
<!ELEMENT entryFrame (#PCDATA)>
<!ELEMENT entryTab (#PCDATA)>
<!ELEMENT entryDesc (#PCDATA)>
<!ELEMENT isEntryDir (#PCDATA)>
<!ELEMENT isEntryFile (#PCDATA)>
<!ELEMENT frameHome (#PCDATA)>
<!ELEMENT tabHome (#PCDATA)>
<!ELEMENT fileName (#PCDATA)>
<!ELEMENT tabSelectedIndex (#PCDATA)>
<!ELEMENT isFileTask (#PCDATA)>
<!ELEMENT isTabTask (#PCDATA)>
<!ELEMENT isFrameTask (#PCDATA)>
<!ELEMENT dow (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT key (#PCDATA)>
]>
<links>
<link action="entry">
<linkName>
null
</linkName>
<linkPath>
null
</linkPath>
<linkDesc>
null
</linkDesc>
<entryName>
fffffffffffff
</entryName>
<dbName>
bookMarkDB.xml
</dbName>
<dbHome>
C:\Users\Steves\.targetGuide\admin_\admin\Note Folder;fffffffffffff\bookMarkDB
</dbHome>
<entryFrame>
fffffffffffff
</entryFrame>
<entryTab>
Notes Glossary
</entryTab>
<entryDesc>
Enter a Description here and Submit
</entryDesc>
<isEntryDir>
true
</isEntryDir>
<isEntryFile>
false
</isEntryFile>
<frameHome>
C:\Users\Steves\.targetGuide\admin_\admin\Note Folder
</frameHome>
<tabHome>
C:\Users\Steves\.targetGuide\admin_\admin\Note Folder\fffffffffffff
</tabHome>
<fileName>
null
</fileName>
<tabSelectedIndex>
0
</tabSelectedIndex>
<isFileTask>
false
</isFileTask>
<isTabTask>
false
</isTabTask>
<isFrameTask>
true
</isFrameTask>
<dow>
Monday
</dow>
<date>
2013-02-11
</date>
<time>
05:45:00.000
</time>
<key>
zero
</key>
</link>
</links>
[/code]