Return-Path: Delivered-To: apmail-xml-xalan-j-users-archive@xml.apache.org Received: (qmail 35802 invoked by uid 500); 2 May 2003 22:35:08 -0000 Mailing-List: contact xalan-j-users-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list xalan-j-users@xml.apache.org Received: (qmail 35777 invoked from network); 2 May 2003 22:35:07 -0000 Received: from web20514.mail.yahoo.com (216.136.173.246) by daedalus.apache.org with SMTP; 2 May 2003 22:35:07 -0000 Message-ID: <20030502223515.24679.qmail@web20514.mail.yahoo.com> Received: from [161.114.56.102] by web20514.mail.yahoo.com via HTTP; Fri, 02 May 2003 15:35:15 PDT Date: Fri, 2 May 2003 15:35:15 -0700 (PDT) From: peter peter Subject: Serialization giving probem with HashMap To: xalan-j-users@xml.apache.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-68672971-1051914915=:23817" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --0-68672971-1051914915=:23817 Content-Type: text/plain; charset=us-ascii 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.(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. --0-68672971-1051914915=:23817 Content-Type: text/html; charset=us-ascii
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. --0-68672971-1051914915=:23817--