Java XML解析
Java ZIP文件解压 备忘笔记
pom引用:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency>
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private IndexXml getIndexXml(String xmlStr) throws DocumentException { IndexXml result = new IndexXml(); Document document = DocumentHelper.parseText(xmlStr); Element rootElement = document.getRootElement(); Element element = rootElement.element("DATASET"); result.setName(element.attribute("name").getValue()); result.setVer(element.attribute("ver").getValue()); result.setRmk(element.attribute("rmk").getValue()); Element elementData = element.element("DATA"); Iterator iter = elementData.elementIterator("DATASET"); List<BcpInfo> bcpList = new ArrayList<BcpInfo>(); result.setBcps(bcpList); while (iter.hasNext()) { //遍历BCP文件描述信息 BcpInfo bcpInfo = new BcpInfo(); bcpList.add(bcpInfo); Element elementBcp = (Element) iter.next(); Element elementBcp1 = elementBcp.element("DATA"); Iterator iterItem = elementBcp1.elementIterator("ITEM"); while (iterItem.hasNext()) { Element elementItem = (Element) iterItem.next(); if (elementItem.attribute("key").getValue().equals("I010032")) { bcpInfo.setColumnSeparator(elementItem.attribute("val").getValue()); } if (elementItem.attribute("key").getValue().equals("I010033")) { bcpInfo.setRowSeparator(elementItem.attribute("val").getValue()); } if (elementItem.attribute("key").getValue().equals("I010039")) { bcpInfo.setCharset(elementItem.attribute("val").getValue()); } } Iterator iterItem2 = elementBcp1.element("DATASET").element("DATA").elementIterator("ITEM"); while (iterItem2.hasNext()) { Element elementItem2 = (Element) iterItem2.next(); if (elementItem2.attribute("key").getValue().equals("H040003")) { bcpInfo.setPath(elementItem2.attribute("val").getValue()); } if (elementItem2.attribute("key").getValue().equals("H010020")) { bcpInfo.setFileName(elementItem2.attribute("val").getValue()); } if (elementItem2.attribute("key").getValue().equals("I010034")) { bcpInfo.setRowCount(elementItem2.attribute("val").getValue()); } } } return result; }