You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by peter peter <ma...@yahoo.com> on 2003/05/03 00:35:15 UTC
Serialization giving probem with HashMap
Hi, I am creating a new document and could serialize it without fail. But if I add the created document to the HashMap. and then get the document from hashMap and try to serialize, OutputFormat throws NullPointerException, Here's the exception message--- /*java.lang.NullPointerException
at org.apache.xml.serialize.OutputFormat.whichMethod(Unknown Source)
at org.apache.xml.serialize.OutputFormat.<init>(Unknown Source)*/ Here's the code I am using---> HashMap documentsMap = new HashMap();
Document doc= new DocumentImpl();
Element root = doc.createElement("person"); // Create Root Element
Element item = doc.createElement("name"); // Create element
item.appendChild( doc.createTextNode("Jeff") );
root.appendChild( item ); // Attach another Element - doc.appendChild( root ); // Add Root to Document//add to the HashMap....
documentsMap.put("node1",doc );
try
{
Iterator iterator = documentsMap.entrySet().iterator();
while (iterator.hasNext() )
{
Object key = iterator.next();
doc= (Document)taxonomyNodesMap.get(key);
OutputFormat format = new OutputFormat( doc ); //Serialize DOM
StringWriter stringOut = new StringWriter(); //Writer will be a XMLSerializer serial = new XMLSerializer( stringOut, format );
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize( doc.getDocumentElement());
}
}catch...... Any help will be greatly appreciated.. Regards,Peter
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
Re: Serialization giving probem with HashMap
Posted by peter peter <ma...@yahoo.com>.
Solution is: I should use keySet() instead of entrySet() Regards,
peter peter <ma...@yahoo.com> wrote:Hi, I am creating a new document and could serialize it without fail. But if I add the created document to the HashMap. and then get the document from hashMap and try to serialize, OutputFormat throws NullPointerException, Here's the exception message--- /*java.lang.NullPointerException
at org.apache.xml.serialize.OutputFormat.whichMethod(Unknown Source)
at org.apache.xml.serialize.OutputFormat.<init>(Unknown Source)*/ Here's the code I am using---> HashMap documentsMap = new HashMap();
Document doc= new DocumentImpl();
Element root = doc.createElement("person"); // Create Root Element
Element item = doc.createElement("name"); // Create element
item.appendChild( doc.createTextNode("Jeff") );
root.appendChild( item ); // Attach another Element - doc.appendChild( root ); // Add Root to Document//add to the HashMap....
documentsMap.put("node1",doc );
try
{
Iterator iterator = documentsMap.entrySet().iterator();
while (iterator.hasNext() )
{
Object key = iterator.next();
doc= (Document)taxonomyNodesMap.get(key);
OutputFormat format = new OutputFormat( doc ); //Serialize DOM
StringWriter stringOut = new StringWriter(); //Writer will be a XMLSerializer serial = new XMLSerializer( stringOut, format );
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize( doc.getDocumentElement());
}
}catch...... Any help will be greatly appreciated.. Regards,Peter
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.