public XmlTemplateEngine(String indentation, boolean validating) throws SAXException, ParserConfigurationException { this(new XmlParser(validating, true), new GroovyShell()); this.xmlParser.setTrimWhitespace(true); setIndentation(indentation); }
/** * A helper method to parse the given text as XML. * * @param text the XML text to parse * @return the root node of the parsed tree of Nodes * @throws SAXException Any SAX exception, possibly * wrapping another exception. * @throws IOException An IO exception from the parser, * possibly from a byte stream or character stream * supplied by the application. */ public Node parseText(String text) throws IOException, SAXException { return parse(new StringReader(text)); }
public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException { addTextToNode(); Object nodeName = getElementName(namespaceURI, localName, qName); int size = list.getLength(); Map<Object, String> attributes = new LinkedHashMap<Object, String>(size); for (int i = 0; i < size; i++) { Object attributeName = getElementName(list.getURI(i), list.getLocalName(i), list.getQName(i)); String value = list.getValue(i); attributes.put(attributeName, value); } parent = createNode(parent, nodeName, attributes); stack.add(parent); }
public void myMethod() throws IOException { XmlParser xmlparse; try { xmlparse = new XmlParser(); } catch (XmlPullParserException e) { // handle... } }
private void taskdef(Map<String, String> args) { Set<String> argNames = args.keySet(); if (argNames.equals(ImmutableSet.of("name", "classname"))) { try { String name = args.get("name"); String className = args.get("classname"); addTaskDefinition(name, className); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } } else if (argNames.equals(Collections.singleton("resource"))) { InputStream instr = antlibClassLoader.getResourceAsStream(args.get("resource")); try { Node xml = new XmlParser().parse(instr); for (Object taskdefObject : (NodeList) xml.get("taskdef")) { Node taskdef = (Node) taskdefObject; String name = (String) taskdef.get("@name"); String className = (String) taskdef.get("@classname"); addTaskDefinition(name, className); } } catch (Exception ex) { throw UncheckedException.throwAsUncheckedException(ex); } finally { IOUtils.closeQuietly(instr); } } else { throw new RuntimeException("Unsupported parameters for taskdef(): " + args); } }
public void oncreate(){ // Do something or mostly the basic code // Call the class to initate the connection and get the data FetchList fl = new FetchList(); fl.execute(); } //Always better to use async task for these purposes public class FetchList extends asyncTask<Void,Void,Byte>{ doinbackground{ // this was explained in first step Response res = new Response("url"); String response = res.getResponse(); XmlParser xml = new XmlParser(response); ArrayList<item> itemList = xml.getItemList(); xml.parse(); } }
/** * Parse the content of the specified input source into a tree of Nodes. * * @param input the InputSource for the XML to parse * @return the root node of the parsed tree of Nodes * @throws SAXException Any SAX exception, possibly * wrapping another exception. * @throws IOException An IO exception from the parser, * possibly from a byte stream or character stream * supplied by the application. */ public Node parse(InputSource input) throws IOException, SAXException { getXMLReader().parse(input); return parent; }
private XmlParser newParser() throws Exception { XmlParser xmlParser = new XmlParser(newSaxParser()); xmlParser.setErrorHandler(getErrorHandler()); xmlParser.setTrimWhitespace(!isKeepWhitespace()); return xmlParser; }
public List<String> search(String key, String url){ List<String> items = new ArrayList<String>(); XmlParser parser = new XmlParser(); String xml = parser.getXmlFromUrl(url); // getting XML Document doc = parser.getDomElement(xml); NodeList nl = doc.getElementsByTagName("book"); for(int i = 0; i<nl.getLength();i++){ Element e = (Element) nl.item(i); NodeList n = e.getElementsByTagName("string"); if(parser.getElementValue(n.item(1)).equals(key) || parser.getElementValue(n.item(2)).equals(key) ){ items.add(parser.getElementValue(n.item(0))); } } return items; }
private XmlParser parser() throws Exception { XmlParser xmlParser = new XmlParser(saxParser()); xmlParser.setErrorHandler(new SimpleSaxErrorHandler(LOG)); return xmlParser; }
public class ReadXml { public void doSomeThing(){ File file = new File("PageOutput.txt"); FileOutputStream fos = new FileOutputStream(file); PrintStream ps = new PrintStream(fos); XmlParser read = new XmlParser(); List<Item> readConfig = read.readConfig("UnderMaintenanceConfig.xml"); for (Item item : readConfig) { System.setOut(ps); System.out.println(item); } } }
public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException { addTextToNode(); Object name = getElementName(namespaceURI, localName, qName); int size = list.getLength(); Map attributes = new HashMap(size); for (int i = 0; i < size; i++) { Object attributeName = getElementName(list.getURI(i), list.getLocalName(i), list.getQName(i)); String value = list.getValue(i); attributes.put(attributeName, value); } parent = new Node(parent, name, attributes, new NodeList()); stack.add(parent); }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { addTextToNode(); if (!stack.isEmpty()) { stack.remove(stack.size() - 1); if (!stack.isEmpty()) { parent = stack.get(stack.size() - 1); } } }
.... try { XmlParser xmlparse = new XmlParser(); } catch (XmlPuillParserException e) { // do something } catch (IOException e) { // do something }
/** * Parse the content of the specified URI into a tree of Nodes. * * @param uri a String containing a uri pointing to the XML to be parsed * @return the root node of the parsed tree of Nodes * @throws SAXException Any SAX exception, possibly * wrapping another exception. * @throws IOException An IO exception from the parser, * possibly from a byte stream or character stream * supplied by the application. */ public Node parse(String uri) throws IOException, SAXException { InputSource is = new InputSource(uri); getXMLReader().parse(is); return parent; }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { addTextToNode(); if (!stack.isEmpty()) { stack.remove(stack.size() - 1); if (!stack.isEmpty()) { parent = stack.get(stack.size() - 1); } } }