SAXParserFactory factory = SAXParserFactory.newInstance(); try { InputStream xmlInput = new FileInputStream("theFile.xml"); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new SaxHandler(); saxParser.parse(xmlInput, handler); } catch (Throwable err) { err.printStackTrace (); }
/** * Handles open tag, if its name is <code>entry</code> and has attribute <code>key</code>. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.toLowerCase().equals("entry") && attributes.getLength() > 0) { currentKey = getAttributeValue("key", attributes); if (currentKey != null) { isEntry = true; currentBuffer = new StringBuffer(); } } }
public class SaxParser { public static Vertretungsplan parse(InputStream is) { Vertretungsplan vertretungsplan = null; try { XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); SaxHandler saxHandler = new SaxHandler(); xmlReader.setContentHandler(saxHandler); xmlReader.parse(new InputSource(is)); vertretungsplan = saxHandler.getVertretungsplan(); } catch (Exception ex) { Log.d("XML", "SAXXMLParser: parse() failed"); } return vertretungsplan; } }
/** * Reads XML provided in <code>is</code> input stream and looks for property entries. * All properties are placed to the properties container <code>p</code>. * * Allways returns null and puts all properties to the <code>p</code>. */ @Override protected Properties loadFromXML(final Properties p, final InputStream is) throws IOException { try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xrdr = parser.getXMLReader(); xrdr.setFeature("http://xml.org/sax/features/validation", false); xrdr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final SaxHandler handler = new SaxHandler(); parser.parse(is, handler); p.putAll(handler.getProperties()); } catch (ParserConfigurationException e) { throw new IOException("Could not read xml", e); } catch (SAXException e) { throw new IOException("Could not read xml", e); } return null; }
/** * Reads XML provided in <code>is</code> input stream and looks for property entries. * All properties are placed to the properties container <code>p</code>. * * Allways returns null and puts all properties to the <code>p</code>. */ @Override protected Properties loadFromXML(final Properties p, final InputStream is) throws IOException { try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xrdr = parser.getXMLReader(); xrdr.setFeature("http://xml.org/sax/features/validation", false); xrdr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final SaxHandler handler = new SaxHandler(); parser.parse(is, handler); p.putAll(handler.getProperties()); } catch (ParserConfigurationException e) { throw new IOException("Could not read xml", e); } catch (SAXException e) { throw new IOException("Could not read xml", e); } return null; }
/** * Reads XML provided in <code>is</code> input stream and looks for property entries. * All properties are placed to the properties container <code>p</code>. * * Allways returns null and puts all properties to the <code>p</code>. */ @Override protected Properties loadFromXML(final Properties p, final InputStream is) throws IOException { try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xrdr = parser.getXMLReader(); xrdr.setFeature("http://xml.org/sax/features/validation", false); xrdr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final SaxHandler handler = new SaxHandler(); parser.parse(is, handler); p.putAll(handler.getProperties()); } catch (ParserConfigurationException e) { throw new IOException("Could not read xml", e); } catch (SAXException e) { throw new IOException("Could not read xml", e); } return null; }
/** * Handles open tag, if its name is <code>entry</code> and has attribute <code>key</code>. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.toLowerCase().equals("entry") && attributes.getLength() > 0) { currentKey = getAttributeValue("key", attributes); if (currentKey != null) { isEntry = true; currentBuffer = new StringBuffer(); } } }
public void makeList(String s){ SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sp = factory.newSAXParser(); XMLReader xmlReader = sp.getXMLReader(); SaxHandler handler = new SaxHandler(); xmlReader.setContentHandler(handler); InputSource is = new InputSource(new StringReader(s)); is.setEncoding("UTF-8"); xmlReader.parse(is); }
/** * Reads XML provided in <code>is</code> input stream and looks for property entries. * All properties are placed to the properties container <code>p</code>. * * Allways returns null and puts all properties to the <code>p</code>. */ @Override protected Properties loadFromXML(final Properties p, final InputStream is) throws IOException { try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xrdr = parser.getXMLReader(); xrdr.setFeature("http://xml.org/sax/features/validation", false); xrdr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final SaxHandler handler = new SaxHandler(); parser.parse(is, handler); p.putAll(handler.getProperties()); } catch (ParserConfigurationException e) { throw new IOException("Could not read xml", e); } catch (SAXException e) { throw new IOException("Could not read xml", e); } return null; }
/** * Handles open tag, if its name is <code>entry</code> and has attribute <code>key</code>. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.toLowerCase().equals("entry") && attributes.getLength() > 0) { currentKey = getAttributeValue("key", attributes); if (currentKey != null) { isEntry = true; currentBuffer = new StringBuffer(); } } }
final ProgressBar bar_progress = (ProgressBar) findViewById(R.id.bar_progress); ProgressFilterInputStream pfis = new ProgressFilterInputStream(getAssets().open("DATA.xml") , bar_progress ); Reader reader = new InputStreamReader(pfis, "UTF-8"); InputSource is = new InputSource(reader); // create the factory SAXParserFactory factory = SAXParserFactory.newInstance(); // create a parser SAXParser parser = factory.newSAXParser(); // create the reader (scanner) XMLReader xmlreader = parser.getXMLReader(); // instantiate our handler SaxHandler myHandler = new SaxHandler(); // assign our handler xmlreader.setContentHandler(myHandler); // perform the synchronous parse xmlreader.parse(is);
/** * Reads XML provided in <code>is</code> input stream and looks for property entries. * All properties are placed to the properties container <code>p</code>. * * Allways returns null and puts all properties to the <code>p</code>. */ @Override protected Properties loadFromXML(final Properties p, final InputStream is) throws IOException { try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xrdr = parser.getXMLReader(); xrdr.setFeature("http://xml.org/sax/features/validation", false); xrdr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final SaxHandler handler = new SaxHandler(); parser.parse(is, handler); p.putAll(handler.getProperties()); } catch (ParserConfigurationException e) { throw new IOException("Could not read xml", e); } catch (SAXException e) { throw new IOException("Could not read xml", e); } return null; }
/** * Handles open tag, if its name is <code>entry</code> and has attribute <code>key</code>. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.toLowerCase().equals("entry") && attributes.getLength() > 0) { currentKey = getAttributeValue("key", attributes); if (currentKey != null) { isEntry = true; currentBuffer = new StringBuffer(); } } }
/** * Handles open tag, if its name is <code>entry</code> and has attribute <code>key</code>. */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.toLowerCase().equals("entry") && attributes.getLength() > 0) { currentKey = getAttributeValue("key", attributes); if (currentKey != null) { isEntry = true; currentBuffer = new StringBuffer(); } } }