For this kind of thing say that this API is arcane and outdated. When we see DOM, we will see that you can have random access to any part of the XML document.
Code:
MyDriver.java
org.xml.sax.Attributes import;
import org.xml.sax.SAXException;
org.xml.sax.helpers.DefaultHandler import;
/ **
* SAX event handler example.
*
* @ Author Xela
*
* /
DefaultHandler MyDriver public class extends (
@ Override
public void startDocument () throws SAXException (
System.out.println ("\ nPrinciple document ...");
)
@ Override
public void EndDocument () throws SAXException (
System.out.println ("\ nFin document ...");
)
@ Override
public void startElement (String uri, String localName, String name,
Attributes attributes) throws SAXException (
System.out.println ("\ nProcesando tag ...");
System.out.println ("\ tNamespace uri:" + uri);
System.out.println ("\ tfirst_name:" + localName);
System.out.println ("\ tfirst_name with prefix:" + name);
/ / Loop through the attributes
System.out.println ("\ tProcesando" + attributes.getLength () + "attributes ...");
for (int i = 0; i <attributes.getLength (); i + +) (
System.out.println ("\ t \ tfirst_name:" + attributes.getQName (i));
System.out.println ("\ t \ tValor:" + attributes.getValue (i));
)
// Also we can get the attributes by name
String value = attributes.getValue ("id");
if (value! = null) (
System.out.println ("\ tid:" + value);
)
)
@ Override
public void characters (char [] ch, int start, int length)
throws SAXException (
System.out.println ("\ nProcesando text within a label ...");
System.out.println ("\ TText:" + String.valueOf (ch, start, length));
)
@ Override
public void EndElement (String uri, String localName, String name)
throws SAXException (
System.out.println ("\ nFin tag ...");
System.out.println ("\ tNamespace uri:" + uri);
System.out.println ("\ tfirst_name:" + localName);
System.out.println ("\ tfirst_name with prefix:" + name);
)
)
As you can see the class in this example is very silly. I'll just putting messages to stdout as they jumping events.
Bookmarks