TestingXML - System.out.println"END" qName public...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; i import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; i import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; i import org.xml.sax.*; import org.xml.sax.helpers.*; i public class TestingXML { p public static void readSAX(File f) throws Exception{ p SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser s = spf.newSAXParser(); S DefaultHandler dh = new DefaultHandler(){ D public void startElement(String u, String ln, String qName, Attributes a){ System.out.println("START: " + qName); } public void endElement(String uri, String localName, String qName){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println("END: " + qName); } public void characters(char ch,int start, int length){ System.out.println("CHARS: "+new String(ch, start, length)); } }; s.parse(f, dh); } public static void readDOM(File f) throws Exception{ p DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder d = factory.newDocumentBuilder(); Document doc = d.parse(f); D System.out.println ("Root: " + doc.getDocumentElement().getNodeName()); S NodeList lst = doc.getDocumentElement().getChildNodes(); N for(int ii=0; ii<lst.getLength();ii++){ Node n = lst.item(ii); System.out.println("Child: " + n.getNodeName() + " --> " + n.getTextContent()); } } }...
View Full Document

This note was uploaded on 04/13/2010 for the course SYSC 2101 taught by Professor Babac during the Winter '10 term at Carleton CA.

Page1 / 2

TestingXML - System.out.println"END" qName public...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online