扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共2页)
具体实现 被观察者对象ParseXMLSubject类:
package test;
import java.io.*;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.*;
public class ParseXMLSubject implements XMLReader {
ContentHandler handler;
String nsu = "";
Attributes atts = new AttributesImpl();
String rootElement = "addressbook";
String indent = "\n ";
public ParseXMLSubject(){
}
public ContentHandler getContentHandler() {
return handler;
}
public void parse(InputSource input) throws IOException, SAXException {
try {
// Get an efficient reader for the file
java.io.Reader r = input.getCharacterStream();
BufferedReader br = new BufferedReader(r);
// Read the file and display it's contents.
String line = br.readLine();
while (null != (line = br.readLine())) {
if (line.startsWith("email:")) {
break;
}
}
if (handler == null) {
throw new SAXException("No content handler");
}
// Note:
// We're ignoring setDocumentLocator(), as well
handler.startDocument();
handler.startElement(nsu, rootElement, rootElement, atts);
output("email", line);
line = br.readLine();
output("html", line);
line = br.readLine();
output("firstname", line);
line = br.readLine();
output("lastname", line);
line = br.readLine();
output("work", line);
line = br.readLine();
output("home", line);
line = br.readLine();
output("fax", line);
line = br.readLine();
output("pager", line);
line = br.readLine();
output("cell", line);
handler.ignorableWhitespace("\n".toCharArray(), 0, // start index
1 // length
);
handler.endElement(nsu, rootElement, rootElement);
handler.endDocument();
} catch (Exception e) {
e.printStackTrace();
}
}
public void parse(String systemId) throws IOException, SAXException {
}
public DTDHandler getDTDHandler() {
return null;
}
public EntityResolver getEntityResolver() {
return null;
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者