<DIV>Hi,<BR>I want to create the following-<BR> <?xml version="1.0" encoding="UTF-8" ?> <BR><DataSet><BR> <user username="userno1" /> <BR></DataSet></DIV>
<DIV>I am reading the attributes for the element user from a user.txt file.<BR>I am getting the IllegalAddException--<BR>The attribute already has an existing parent "user"</DIV>
<DIV>This is my code.<BR>Element root = new Element("DataSet");<BR> Document doc = new Document(root); <BR> Element user = new Element("user");<BR> Attribute userattr = new Attribute(uattr,struser);<BR> FileReader fin = new FileReader("user.txt");<BR> BufferedReader d = new BufferedReader(fin); <BR> String line;<BR> try { <BR> while(( line = d.readLine()) != null){<BR> struser = d.readLine();
<BR> user.setAttribute(userattr);<BR> root.addContent(user);<BR> }<BR> XMLOutputter outputter = new XMLOutputter(" ", true); <BR> FileWriter writer = new FileWriter("Data.xml");<BR> outputter.output(doc, writer);<BR> writer.close();<BR> } catch(FileNotFoundException e) {
<BR> System.out.println("File not found" + fin);<BR> return;<BR> } catch(EOFException eof) {<BR> fin.close();<BR> System.out.println(eof.getMessage());<BR> return;<BR> } catch (java.io.IOException e) {<BR> e.printStackTrace();<BR> } catch(IllegalAddException i) {<BR> System.out.println(i.getMessage());
<BR> } <BR> fin.close();<BR> }<BR>Somebody help me out.<BR>Thank You,<BR>Salil.</DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com">Yahoo! SiteBuilder</a> - Free, easy-to-use web site design software