- All Known Subinterfaces:
- Locator2
- All Known Implementing Classes:
- Locator2Impl, LocatorImpl
- See Also:
- Top Examples, Source Code,
startDocument , ContentHandler.setDocumentLocator(org.xml.sax.Locator)
int getColumnNumber() - See Also:
getLineNumber()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getLineNumber() - See Also:
getColumnNumber()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1579]Creates a validating SAX parser By Anonymous on 2005/11/04 20:23:08 Rate
import javax.xml.parsers.*; import org.xml.sax.*; import org.xml.sax.helpers.*; public class SAXValidator extends DefaultHandler { public void warning ( SAXParseException ex ) throws SAXException { System.out.println ( "Warning at Line " + locator.getLineNumber ( ) + ":" ) ; System.out.println ( " " + ex.getMessage ( ) ) ; } public void error ( SAXParseException ex ) throws SAXException { System.out.println ( "Error at Line " + locator.getLineNumber ( ) + ":" ) ; System.out.println ( " " + ex.getMessage ( ) ) ; } public void setDocumentLocator ( Locator locator ) { this.locator = locator; } public static void main ( String [ ] args ) { try { if ( args.length == 0 ) { System.out.println ( "Usage: " + "java SAXValidator < XML filename > " ) ; System.exit ( -1 ) ; } SAXParser parser = getSchemaValidatingSAXParser ( ) ; parser.parse ( new java.io.File ( args [ 0 ] ) , new SAXValidator ( ) ) ; } catch ( Exception ex ) { ex.printStackTrace ( ) ; } } public static SAXParser getSchemaValidatingSAXParser ( ) { SAXParser result = null; try { SAXParserFactory factory = SAXParserFactory.newInstance ( ) ; factory.setValidating ( true ) ; factory.setFeature ( "http://xml.org/sax/features/namespaces", true ) ; result = factory.newSAXParser ( ) ; result.setProperty ( "http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema" ) ; } catch ( Exception ex ) { System.out.println ( "This parser apparently can't " + "validate against XML Schema." ) ; System.out.println ( " ( " + ex.getMessage ( ) + " ) " ) ; } return result; } private Locator locator; }
String getPublicId() - See Also:
getSystemId()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
String getSystemId() - See Also:
getPublicId()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
| Popular Tags |