List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:Main.java
public static void main(String[] argv) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); String features[] = { "http://xml.org/sax/features/namespaces", "http://xml.org/sax/features/namespace-prefixes", "http://xml.org/sax/features/string-interning", "http://xml.org/sax/features/validation", "http://xml.org/sax/features/external-general-entities", "http://xml.org/sax/features/external-parameter-entities", "http://xml.org/sax/features/lexical-handler/parameter-entities", }; for (int i = 0; i < features.length; i++) { System.out.print("\t- '" + features[i] + "' is "); System.out.println("'" + factory.getFeature(features[i]) + "'"); }/*ww w. j a va 2s.c om*/ }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SAXParserFactory spf = SAXParserFactory.newInstance(); System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ") + "be namespace aware"); System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML"); SAXParser parser = null;//ww w.jav a2 s. c o m parser = spf.newSAXParser(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true);/*w w w .j a v a2 s .c o m*/ spf.setValidating(true); System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ") + "be namespace aware"); System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML"); SAXParser parser = spf.newSAXParser(); System.out.println("Parser object is: " + parser); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.parsers.SAXParser"); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); }
From source file:Main.java
public static void main(String[] args) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); SaxHandler handler = new SaxHandler(); parser.parse("sample.xml", handler); }
From source file:Main.java
public static void main(String args[]) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { System.out.println(qName); }// www . j a va 2 s . c o m public void characters(char ch[], int start, int length) throws SAXException { System.out.println(new String(ch, start, length)); } }; saxParser.parse(args[0], handler); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); SaxHandler handler = new SaxHandler(); parser.parse("sample.xml", handler); }
From source file:Main.java
public static void main(String[] args) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true);/*w ww .j av a 2 s. co m*/ SAXParser parser = factory.newSAXParser(); parser.parse("sample.xml", new SampleOfXmlLocator()); }
From source file:Main.java
public static void main(String[] args) throws Exception { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); parser.parse(new File("test.xml"), new DefaultHandler() { @Override/*from www. j a va 2 s . c o m*/ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { if (qName.equals("passenger")) { System.out.println("id = " + atts.getValue(0)); } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { } @Override public void characters(char[] ch, int start, int length) throws SAXException { String text = new String(ch, start, length); if (!text.trim().isEmpty()) { System.out.println("name " + text); } } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true);/*from w w w .j av a 2 s . c o m*/ SAXParser parser = factory.newSAXParser(); SaxHandler handler = new SaxHandler(); parser.parse("sample.xml", handler); }