public static List<SheetDetail> parse(String xml) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(xml))); Node rootNode = null; for (Node node = doc.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getNodeType() == Node.ELEMENT_NODE && "opDetail".equals(node.getNodeName())) { rootNode = node; break; } } if (rootNode == null) { return null; } List<SheetDetail> list = new ArrayList<SheetDetail>(); for (Node node = rootNode.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getNodeType() == Node.ELEMENT_NODE && "recordInfo".equals(node.getNodeName())) { SheetDetail sheet = parseRecordNode(node); list.add(sheet); } } return list; } catch (Exception e) { logger.error("", e); return null; } }
SheetDetail为实体类。