文件名称:XPathUtil,根据Xpath解析xml文件
文件大小:4KB
文件格式:JAVA
更新时间:2021-02-04 08:49:12
Xpath xml文件 解析
根据xmlPath路径,找到对应的xml文件,进行解析!之前找了好多感觉和自己的需求不太一样,这个可以根据Xpath解析出来xml里所有的信息,十分好用 举个例子 xmlPath = "E://upload/xml/1580242.163.xml"; XPathUtil util = XPathUtil.newInstance(xmlPath); Product product = new Product(); String title = util.getSingleValue("book/title"); product.setTitle(title); String classification = util.getSingleValue("/book/info/classification"); product.setFenlei(classification); String language = util.getSingleValue("/book/info/language"); String yuYan = XPathUtil.LANUAGE_MAP.get(language); product.setYuYan(yuYan); String personname =util.getSingleValue("/book/info/authorgroup/author/personname"); String role = util.getDomAttribute("/book/info/authorgroup/author", "role"); String author = personname + " " + role; product.setAuthor(author); String personblurb = util.getSingleValue("/book/info/authorgroup/author/personblurb"); product.setAuthorRemarks(personblurb);