zoukankan      html  css  js  c++  java
  • dom4j-full.jar 解析 XML

    dom4j-full.jar 解析 XML

    public Document getDocument() throws DocumentException
    {
    SAXReader read=new SAXReader();
    return	read.read(this.getClass().getResourceAsStream("/course.xml"));
    
    }
    
    public List<Course> getAllCourse()
    {
    List<Course> list=new ArrayList<Course>();
    try {
    Document doc=this.getDocument();
    
    Element root=doc.getRootElement();
    List<Element> courseNodes=root.elements("course");
    for (Element courseNode:courseNodes)
    {
    Course course=new Course();
    course.setName(courseNode.elementTextTrim("name"));
    course.setDate(courseNode.elementTextTrim("date"));
    course.setDesc(courseNode.elementTextTrim("desc"));
    list.add(course);
    }
    } catch (DocumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return list;
    }
    

      

    <?xml version="1.0" encoding="UTF-8"?>
    <courses>
    <course>
    <name>JAVASE</name>
    <date>23</date>
    <desc>JAVA语言入门课程</desc>
    </course>
    <course>
    <name>JAVAEE</name>
    <date>31</date>
    <desc>JAVA语言高级课程</desc>
    </course>
    </courses>
    

      

  • 相关阅读:
    CF1260F
    牛客挑战赛34 A~E
    CSP-S2019游记&拆塔记
    6424. 【NOIP2019模拟2019.11.13】我的订书机之恋
    CF1257E/F
    6423. 【NOIP2019模拟11.11】画
    1222/2516. Kup
    Comet OJ
    浅析CSS定位
    css文字颜色渐变的3种实现
  • 原文地址:https://www.cnblogs.com/zhuawang/p/3306660.html
Copyright © 2011-2022 走看看