项目学习主题七:读取xml
来源:互联网 发布:恐怖悬疑电影 知乎 编辑:程序博客网 时间:2024/06/12 00:49
读取xml:
public class Readxml { class XMLHandler extends DefaultHandler { public Map<String,String> resultMap; private boolean title = false; public String searchItem; // Called at start of an XML document @Override public void startDocument() throws SAXException { resultMap=new HashMap<String,String>(); } // Called at end of an XML document @Override public void endDocument() throws SAXException { } @Override public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { // Using qualified name because we are not using XMLs prefixes here. if (!qName.equals("")) { searchItem=qName; title = true; } } @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { // End of processing current element if (title) { title = false; } } @Override public void characters(char[] ch, int start, int length) { // Processing character data inside an element if (title) { String searchResult = new String(ch, start, length); if(!searchResult.equals("")) resultMap.put(searchItem,searchResult); } } } /** * This function is used to get informations from a certain XML. */ public static Map<String,String> getXmlInfo(String xmlName) throws SAXException, IOException { XMLReader parser = XMLReaderFactory.createXMLReader(); XMLHandler xmlHandler = (new Readxml()).new XMLHandler(); parser.setContentHandler(xmlHandler); parser.parse("./conf/"+xmlName); return xmlHandler.resultMap; } }
0 0
- 项目学习主题七:读取xml
- 项目学习主题
- 项目主题学习:js
- 项目学习主题四:Activedirectory
- 深入浅出学习Struts1框架(七):ActionServlet实例化之读取struts-config.xml配置文件
- 深入浅出学习Struts1框架(七):ActionServlet实例化之读取struts-config.xml配置文件
- C#学习:读取XML
- XML学习基础(七)
- 七_第零章XML学习
- 学习XML之七:XML 验证
- cordova学习七 项目打包
- 项目学习主题一:java mail
- delphi 学习 xml文件读取
- jdom学习:读取xml文件
- jdom学习:读取xml文件
- jdom学习:读取xml文件
- jdom学习:读取xml文件
- jdom学习:读取xml文件
- ANT自动打包
- [转]通过32bit Winpe 安装64bit windows2008
- Linux 编译OpenJDK
- C++11 中的线程、锁和条件变量
- C或C++编程中使用头文件的顺序
- 项目学习主题七:读取xml
- PDO处理事务部分的报错 :Uncaught exception 'PDOException' with message There is no active transaction
- Iperf 源代码分析(一)
- Android解析json
- IT招聘量超越房地产 聚焦未来三大热门领域
- jquery grid
- 让人爱不释手的13套精美 Web 应用程序图标素材
- MFC 里的 CFile 类的一个函数 CreateFile
- 大家好 新人报道