利用java Api解析XML
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Usage: You can get a instance of Document from a string of xml.
* This class supply some method to read a document.
*
*/
public class XMLParser {
/**
* Get a instance of Document from a string of xml.
*
* @param xmlStr
* @return Document
*/
public static Document parse(String xmlStr) {
if (xmlStr == null) {
return null;
}
StringReader reader = new StringReader(xmlStr);
InputSource source = new InputSource(reader);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
if(builder == null){
return null;
}
Document doc = null;
try {
doc = builder.parse(source);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return doc;
}
/**
* Get Item Value.
* @param node
* @return String
*/
public static String getItemValue(Node node){
String value = "";
if(node == null){
retur
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
http://www.gotapi.com/
语言:英语
简介:HTML,CSS,XPATH,XSL,JAVASCRIPT等API的查询网站。
http://www.w3schools.com/
语言:英语
简介:W3C制定的标准诸如XML,HTML,XSL等等的在线学习教程。
http://www.xml.org.cn/
语言:中文
简介:可以说是XML的中国官方网吧。W3C ......
repaint 对组件进行重绘,比如一个panel,当你remove掉panel里面的一个组件时,你必须调用repaint方法才能对panel进行重绘,进行刷新,你想要删除的组件才能在界面上消失。
revalidate 对组件进行验证,比如一个panel,当你remove掉panel里面的一个组件时,当你调用revalidate方法后,panel的布 ......
事件源负责产生事件
事件类:定义事件的特征;
监听器接口:定义监听器应该实现的功能;
监听器:实现监听器接口,监听事件的发生并作出响应;
所有的事件类必须继承Java事件基类,即java.util.EventObject;EventObject(Object source)是EventObject唯一的构造方法,这意味着所有事件必须在实例化时就指定事件源 ......
java中的事件机制的参与者有3种角色:
1.event object:就是事件产生时具体的“事件”,用于listener的相应的方法之中,作为参数,一般存在与listerner的方法之中
2.event source:具体的接受事件的实体,比如说,你点击一个button,那么button就是event source,这样你必须使button对某些事件进行相应,你就需 ......