Skip to content
Advertisement

How to pars inner XML Tags with SAX

I am trying to read data from an XML file by using SAX. But i cant figure out how to handle the inner <Path> Tag…

How to do pars the inner path element?

This is my XML file.

JavaScript

Here the neccessary java code snippets.

JavaScript

I dont feel like adding the following code is the right approach at all …

JavaScript

I think i have to trigger new qName somehow … but i dont know how. Than i would just check for backup and than inside the backup i would than run an

JavaScript

Also i am asking myself if i should allready handle Attributes inside the startElement or at the characters method.

Advertisement

Answer

On style:

  • Arrays

    JavaScript
  • Variable and method names are camel case with a starting small letter.

  • Indentation: 4 spaces

    Probably a measure to have less nested blocks.

  • Primitive types boolean, int, double better than Object wrappers Boolean, Integer, Double.

Some issues: `characters can be called more than once, deliver just a partial text piece. The parsing with startElement events are tiresome

Now to collect characters:

JavaScript

You’ll need endElement too:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement