localhost sqlname username passWord
import org.xml.sax.Attributes;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.SAXException; import java.util.Properties;//使用DefaultHandler的好處是不必陳列出所有方法,public class ConfigParser extends DefaultHandler{////定義一個Properties 用來存放dbhost dbuser dbpassword的值private Properties props;private String currentSet;private String currentName;private StringBuffer currentValue = new StringBuffer();//構建器初始化propspublic ConfigParser(){this.props = new Properties();}public Properties getProps(){return this.props;}//定義開始解析元素的方法。 這里是將中的名稱xxx提取出來。public void startElement(String uri, String localName,String qName, Attributes attributes) throws SAXException{currentValue.delete(0, currentValue.length());this.currentName =qName;}//這里是將 結束后,將之前的名稱和值一一對應保存在props中public void endElement(String uri,String localName, String qName)throws SAXException {props.put(qName.toLowerCase(), currentValue.toString().trim());}}之間的值加入到currentValuepublic void characters(char[] ch,int start, int length) throws SAXException{ currentValue.append(ch, start, length);}//在碰到
import java.util.Properties;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import java.net.URL;public class ParseXML
新聞熱點
疑難解答