Sax解析xml

来源:互联网 发布:村嶋孟 知乎 编辑:程序博客网 时间:2024/06/10 01:22

<?xml version="1.0" encoding="UTF-8"?>
<xml-body>
 <!-- 内部服务器 -->
 <properties>
  <properties-name>internalEnabled</properties-name>
  <properties-value>true</properties-value>
 </properties>

</xml-body>

SAXReader reader = new SAXReader();
  Document doc = reader.read(new File(L99ActionSupport.systemApplication.getRealPath("/"),"WEB-INF/classes/system-config.xml"));
  Element root = doc.getRootElement();
  Element foo;
  int nx = 0;
  for (Iterator i = root.elementIterator("properties"); i.hasNext();) {
   nx++ ;
   foo = (Element) i.next();
   L99ActionSupport.systemApplication.setAttribute(foo.elementText("properties-name"), foo.elementText("properties-value"));
  }

原创粉丝点击