[jdom-interest] IllegalAddException
Phill_Perryman at Mitel.COM
Phill_Perryman at Mitel.COM
Mon Sep 1 06:44:34 PDT 2003
You cannot keep using the same attribute and element each time, you need to
create new ones
Document doc = new Document(root);
FileReader fin = new FileReader("user.txt");
BufferedReader d = new BufferedReader(fin);
String line;
try {
while(( line = d.readLine()) != null){
Element user = new Element("user");
user.setAttribute("username", line);
root.addContent(user);
}
/Phill
IS Dept, Software Engineer.
phill_perryman at mitel.com
http://www.mitel.com
Tel: +44 1291 436023
salil khanwalkar
<k_salil at yahoo.com To: jdom-interest at jdom.org
> cc:
Sent by: Subject: [jdom-interest] IllegalAddException
jdom-interest-admi
n at jdom.org
01/09/2003 14:20
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){
= 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
More information about the jdom-interest
mailing list