[jdom-interest] IllegalAddException

salil khanwalkar k_salil at yahoo.com
Mon Sep 1 06:20:06 PDT 2003


Hi,
I want to create the following-
  <?xml version="1.0" encoding="UTF-8" ?> 
<DataSet>
  <user username="userno1" /> 
</DataSet>
I am reading the attributes for the element user from a user.txt file.
I am getting the IllegalAddException--
The attribute already has an existing parent "user"
This is my code.
Element root = new Element("DataSet");
        Document doc = new Document(root);     
        Element user = new Element("user");
        Attribute userattr = new Attribute(uattr,struser);
        FileReader fin = new FileReader("user.txt");
        BufferedReader d = new BufferedReader(fin);        
        String line;
        try { 
            while(( line = d.readLine()) != null){
                struser = d.readLine();              
                user.setAttribute(userattr);
                root.addContent(user);
            }
            XMLOutputter outputter = new XMLOutputter("  ", true);        
            FileWriter writer = new FileWriter("Data.xml");
            outputter.output(doc, writer);
            writer.close();
        } catch(FileNotFoundException e) {                
            System.out.println("File not found" + fin);
            return;
        } catch(EOFException eof) {
            fin.close();
            System.out.println(eof.getMessage());
            return;
        } catch (java.io.IOException e) {
            e.printStackTrace();
        } catch(IllegalAddException i) {
            System.out.println(i.getMessage());            
        }        
        fin.close();
    }
Somebody help me out.
Thank You,
Salil.


---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030901/e03867ca/attachment.htm


More information about the jdom-interest mailing list