I'm working on parsing the following XML http://api.eve-online.com/account/Chara ... 36GO2lvQNM
I retrieve the XML and I wrote a parser that extends from DefaultHandler. Now everything works fine except I want to get the complete contents of ever <row .... /> and set all the different elements in a model. But startElement(...) only goes through the tags not the complete contents of the tag.
Using java Syntax Highlighting
- public class CharacterSheetParser extends DefaultHandler {
- private String url;
- private StringBuilder text;
- private Characters characters = new Characters();
- private Character characterModel;
- private boolean fillingCharacter;
- public CharacterSheetParser(String url) {
- this.url = url;
- }
- /**
- * Read the url and parse the XML
- *
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
- */
- public void parse() throws ParserConfigurationException, SAXException,
- IOException {
- InputStream urlInputStream = null;
- SAXParserFactory spf = null;
- SAXParser sp = null;
- URL url = new URL(this.url);
- urlInputStream = url.openConnection().getInputStream();
- spf = SAXParserFactory.newInstance();
- if (spf != null) {
- sp = spf.newSAXParser();
- sp.parse(urlInputStream, this);
- }
- if (urlInputStream != null)
- urlInputStream.close();
- }
- public void startElement(String uri, String name, String qName,
- Attributes atts) {
- // When a result is found the
- if (name.trim().equals("row")) {
- this.characterModel = new Character();
- this.fillingCharacter = true;
- }
- }
- public void endElement(String uri, String localName, String qName) {
- if (localName.equalsIgnoreCase("row")) {
- this.characters.addCharacter(characterModel);
- this.fillingCharacter = false;
- }
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
So what I want to do is get the "name" element inside the row-tag and set it in this.characterModel.setName(..) and so on.
How can I get to those elements?
Thans again,
Rick


