Determining the Parsing Location of an XML SAX Parser

To get the current URI and location of a SAX parser during parsing, you need to obtain a Locator object. This object can be obtained by installing a ContentHandler and overriding the setDocumentLocator() method. The SAX parser will call this method and deliver the Locator object that you can use anytime it delivers an event (i.e., invokes a callback method in a handler). This method will be called before any other ContentHandler method.

Note: Not all SAX parser support a Locator. If it doesn't, the setDocumentLocator() method will not be called.

This example captures the Locator object and uses it whenever it gets a startElement event.

// Create a handler for SAX events DefaultHandler handler = new MyHandler(); // Parse an XML file using SAX; // The Quintessential Program to Parse an XML File Using SAX parseXmlFile("infilename.xml", handler, false); // This class listens for startElement SAX events static class MyHandler extends DefaultHandler { Locator locator; public void setDocumentLocator(Locator locator) { this.locator = locator; } // This method is called when an element is encountered public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { if (locator != null) { int col = locator.getColumnNumber(); int line = locator.getLineNumber(); String publicId = locator.getPublicId(); String systemId = locator.getSystemId(); } } }

Comments

3 Sep 2010 - 3:23am by Anonymous (not verified)

Woods' name atop the leaderboard.
In cartier brooch his first tournament since his miu miu heels divorce, Woods finally looked like fendi baguette the No. 1 player in miu miu clothes the world Thursday at the miu miu clutch Barclays when he opened with miu miu wallets a 6-under 65, his lowest replica cartier score of the year, to piaget watches share the lead with Vaughn vintage tudor watch Taylor. It was his first ugg short boots time leading after any round tiffany and co necklaces on the PGA Tour since miu miu sunglasses the Tour Championship last September.
"It's bottega veneta bags exciting to hit the ball longines flagship watches flush again," Woods said. "It's miu miu shoes something I've been missing all bag replica year."
He didn't miss much at prada fairy bag Ridgewood Country Club. Woods hit loewe bags all but one fairway and replica cartier putted for birdie on all miu miu bow bag but two holes. And while miu miu men's shoes he hit his driver only cartier replica jewelry twice, they were two of miu miu handbag his best shots of the links jewelry day  including on the coach baby bag 291-yard fifth hole, where his cartier love necklace drive landed pin-high and settled rolex for sale 15 feet away.
Was it just tissot t-touch a coincidence that his game rolex for sale showed up so soon after

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.