---
title: "webservice  读取xml文件"
author: "jayyunfei"
date: "2014-06-13T10:09:47Z"
tags: ["WebService"]
categories: ["编程语言"]
slug: "webservice-xml"
draft: false
lastmod: "2014-06-13T10:09:47Z"
id: 2079062
url: "https://jayyunfei.iteye.com/blog/2079062"
---

\[code="java"] SAXBuilder saxBuilder = new SAXBuilder(); Document doc = null; try { doc = saxBuilder.build("D:\\\\re.xml"); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Format format = Format.getPrettyFormat(); //配置xml文档的字符为gb2312，解决中文问题 format.setEncoding("gb2312"); XMLOutputter xmlout = new XMLOutputter(format); ByteArrayOutputStream bo = new ByteArrayOutputStream(); try { xmlout.output(doc,bo); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String xmlStr = bo.toString(); XmlparseUtil xmlUtil = new XmlparseUtil(); List&gt; mapList = new ArrayList&gt;(); List datasetList = new ArrayList(); // holeHostDatasetService.saveDatasets(datasetList); List&gt; secList = new ArrayList&gt;(); try { secList = xmlUtil.xmlElementsm(xmlStr); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { mapList = xmlUtil.xmlElementsm(xmlStr); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i