Jsp My Titles Java
From Fxp Wiki
package vendo; import org.apache.xerces.parsers.SAXParser; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import java.io.*; public class MyTitles extends DefaultHandler { private Writer out; String local0=""; // constructor public MyTitles (String xmlFile, Writer out) { this.out = out; // create a Xerces SAX parser SAXParser parser = new SAXParser(); // set the content handler parser.setContentHandler(this); // parse the document try { parser.parse(xmlFile); out.flush(); } catch (SAXException e) { // something went wrong! } catch (IOException e) { // something went wrong! } } // call at document start public void startDocument() { try { out.write ("<h1>Document begins</h1><br>"); } catch (IOException e) { // do nothing } } // call at element start public void startElement (String uri, String local, String qName, Attributes atts) { try { out.write ("<h2>Element begins: \"" + local + "\"</h2>"); out.write ("<ul><li>uri = " + uri + "</li><li>local = " + local + "</li><li>qName = " + qName + "</li></ul>"); if (local.equals("titles")){ local0 = local; } String AttributeName,AttributeType,AttributeValue = ""; for (int i = 0; i < atts.getLength(); i++) { AttributeName = atts.getLocalName(i); AttributeType = atts.getType(AttributeName); AttributeValue = atts.getValue(AttributeName); out.write ("<h3>Attribute: \"" + AttributeName + "\"<br>"); out.write (" Type: \"" + AttributeType + "\"<br>"); out.write (" Value: \"" + AttributeValue + "\"<br></h3>"); } } catch (IOException e) { // do nothing } } // call when cdata found public void characters(char[] text, int start, int length) { try { String Content = new String(text, start, length); if (!Content.trim().equals("")){ out.write("<h4>Character data: \"" + Content + "\"<br></h4>"); } } catch (IOException e) { // do nothing } } // call at element end public void endElement (String uri, String local, String qName){ try { out.write("<h2> Element ends: \"" + local + "\"<br></h2>"); } catch (IOException e) { // do nothing } } // call at document end public void endDocument() { try { out.write ("<h1>Document ends</h1><br>"); } catch (IOException e) { // do nothing } } }
Categories: Jspwiki | Wikis | Java | Source Code
