Android Tutorial XmlSax - Exposing the Parser at work

XmlSax - Exposing the Parser at work

I wanted to understand how the XmlSax worked so as to fully understand how to write the code to access the different elements.

Found an example on the Forum of an xml document that was suitable to work with and built this program.

The program I made is attached. Open the Files folder and obtain a copy of the file 1.xml to the desktop.

I right click this file and ask for 'Open with' Internet Explorer. This shows the xml document and makes it easier to follow the program as the Passer steps through the document.

1. Set the IDE to DEBUG mode.
2. Click in the left margin of the IDE on lines 46 and 64 to set breakpoints.
3. Select Logs in the right hand side Tab.
4. Click Connect button.
5. Click the 'Compile and Run' option

The program runs down to the first Breakpoint at line 46.
Look in the Logs panel and it shows a Start Element has been passed by the Passer.
The Logs panel shows the Start Element read by the Parser is 'data' and that the Passer.Parents List contains nothing.

Click the F5 key to Continue the debugger.
The Passer moves through the second line of the document and finds another Start Element.
The Logs panel shows the Start Element read by the Parser is 'day' and that the Passer.Parents List contains one item which is 'data'.

Click F5 to allow the Passer to read the next element in the document.
Passer again reads a Start Element - 'name', and shows two items in the Passer.Parents List. They are 'data' and 'day'.

Keep clicking the F5 key to have the Passer read the next line of the document and observe the output in Logs panel.

When the debugger stops on a breakpoint it turns the line YELLOW to show where the debug operation is in the program.

This has helped me to understand using the Parents List Index for the following type of code.

If parser.Parents.IndexOf("activity") > -1 Then

All elements that are children of 'activity' are read until the end element of 'activity' is read.
 

Attachments

  • MyXmlTest.zip
    6.6 KB · Views: 502
  • xml2_ide.png
    xml2_ide.png
    95 KB · Views: 494
Top