在自己弄的xml模仿的

前端之家收集整理的这篇文章主要介绍了在自己弄的xml模仿的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public void testReadXML(){ Map<String,String> map=new HashMap<String,String>(); SAXReader reader = new SAXReader(); // User.hbm.xml表示你要解析的xml文档 Document document = null; File file = new File( "D:\\MyEclipseWorkPalce2014\\xmlparse\\src\\MyXml.xml"); try { document = reader.read(file); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } Element rootElt = document.getRootElement(); // 获取根节点 for (Iterator iter = rootElt.elementIterator(); iter.hasNext();) { Element element = (Element) iter.next(); if(element.getName().equals("appSettings")){ for (Iterator iterInner = element.elementIterator(); iterInner .hasNext();) { Element elementInner = (Element) iterInner.next(); if (elementInner.getName().equals("add")) { // Attribute leaderAttr=elementInner.attribute("key"); // String leader = leaderAttr.getValue(); Attribute key = elementInner.attribute("key"); String keyN = key.getValue(); System.out.println("key"+"..."+keyN); Attribute value = elementInner.attribute("value"); String valueN = value.getValue(); map.put(keyN,valueN); } } } } System.out.println("SitesqlServer+"+map.get("SitesqlServer")); } 原文链接:https://www.f2er.com/xml/298069.html

猜你在找的XML相关文章