java

private static String SERVICES_HOST = "链接方式

 /**
  *
  * @param starDate 开始时间
  * @param endDate 结束时间
  * @param url webSerivce地址
  * @return List<WebServiceTimeProjectBean> 集合数据列表(WebServiceTimeProjectBean实体类)
  */
public static List getProjectWebServiceXML(String starDate,String endDate,String url){
Document document = getDocument(url);
Element root = document.getDocumentElement();
NodeList nodeList = root.getElementsByTagName_r("Table");//得到标签名
return new XmlReader().getProjectWebServiceBean(nodeList);
}

private static Document getDocument(String URL) {
Document document = null;
DocumentBuilderFactory documentBF = DocumentBuilderFactory.newInstance();
documentBF.setNamespaceAware(true);
try {
DocumentBuilder documentB = documentBF.newDocumentBuilder();
InputStream inputStream = getInputStream(URL);
document = documentB.parse(inputStream);
inputStream.close();
} catch (DOMException e) {
e.printStackTrace();
return null;
} catch (ParserConfigurationException e) {
e.printStackTrace();
return null;
} catch (SAXException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
return document;
}


private static InputStream getInputStream(String url) {
InputStream inputStream = null;
try {
URL urlObj = new URL(url);
URLConnection urlConn = urlObj.openConnection();
urlConn.setRequestProperty("Host", SERVICES_HOST);//连接方式
urlConn.connect();
inputStream = urlConn.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return inputStream;
}

你可能感兴趣的:(java)