XML parser and writer not working.
I'm getting a SAXException. It says that my XML is not well formed. I think I know what's wrong but don't know how to handle the issue. It might be that I'm using a String and converting it to a boolean. I just used an example that I found. I think It's not reading/writing attributes properly.
I think it's my XML writer that's the issue. I'm trying to generate XML when something is saved and later read the XML to load the data back into the JTables.
I think that it's going haywire around this line and that it's causing an exception to be thrown. I have run several tests on different parts of my system. They all work except the actual test that goes in the jarfile. Thus, it seems that there is a problem with the XML part.
Here's where I think things are going wrong:
for (int i =0; i < p.getPrayerList().getPrayerCount(); i++)
pw.println("<prayer text=" + String.valueOf('"') + p.getPrayerList().getPrayerTextAt(i) + String.valueOf('"') + " prayedforyet = " +
p.getPrayerList().getPrayerPrayedForAt(i) + String.valueOf('"') + "</prayer>");
Also, I read the stuff in with this part:
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
tmp = new Person();
tempPL = tmp.getPrayerList();
I think it's a simple misunderstanding of how attributes and stuff work. I think it's not realizing that the tag ends when I read in the "prayer" tag and thinking that the "text" attribute is part of the tag. I KNOW the issue is going wrong here. When I comment out that for loop, the problem disappears.
How to get it to read it properly? I'm not sure how to read and write the tags. It could be that I've added an extra space or something in the XML writer. The dumbest things mess up XML files. :(
How would you read a tag with attributes and later write it back to the xml file so that it is well formed.
I am either forgetting a tag somewhere or it is the attribute causing an issue. I don't know why else it wouldn't be well formed. The code before it compiled when I used it before I added the stuff the new stuff (it not only compiled, it ran fine). That previous code is not the issue.
I checked out what it's printing out, did find a few errors, but the issue is still there.
<prayer text="" prayedforyet ="false"></prayer>
It seems well formed but I can't figure out why it's going wrong on the read in. It can't find it and loses the info when I read it in.
My other classes are working I think so they're not the issue. It was working fine when I just autocoded it but when I actually populated it with the data from the XML, then it broke all of a sudden.
Perhaps I should delete the xml file. Maybe there was something glitchy in there and it will go away if I just start anew.
Unless I SHOULD have done the xml for the "prayer" tag in the endElement() method instead of the startElement(), I can't see anything wrong with the endElement() method as it doesn't deal with data in the problem area.
--- Update ---
Well, all I needed to do was delete the xml file as it was because of the formatting of the old xml file. I seem to have stopped the problem. It seems that it now will work. Another feature seems to work now. :) :) :) :)
I'll come back if it gives problems again.