本篇文章將講述如何通過axis取發布的Web services
涉及到的知識有
AXIS
SAXBuilder
xml
步驟如下
必備條件axis開源包
A)
AXIS_HOME=C:\AXIS
AXIS_CLASSPATH=
然後加入到PATH當中
注意
B)
java org
然後就會在這個<名稱
xxxx
xxxxLocator
xxxxSoap
xxxxSoapStub
其次還有以下劃線_xxxx????
SearchFlightInfo
SearchFlightInfoLocator
SearchFlightInfoSoap
SearchFlightInfoSoapStub
_GetFlightInfoResponse_GetFlightInfoResult
_GetstrFlightInfo
_GetstrFlightInfoResponse
C)
基本思想是從得到web services後取得他的主體信息(返回的數據信息)
如下是序列化對象的代碼
java 代碼
try {
/**
* 取得前台的參數
*/
String planDate = request
String flyNo = request
/**
* 按照最新版本制作
*/
SearchFlightInfo service = new SearchFlightInfoLocator();
SearchFlightInfoSoap client = service
_GetFlightInfoResponse_GetFlightInfoResult FOCInfo=client
String ErrorInfo = client
MessageElement[] FOCElement = FOCInfo
List FOCElementHead = FOCElement[
List FOCElementBody = FOCElement[
if (FOCElementBody
//無返回記錄
return mapping
}
String nn = FOCElementBody
String path = request
CommonTools
/**
* 使用DOM
*/
//String path = request
Vector OutFoc = CommonTools
request
if (request
return mapping
}
return mapping
} catch (Exception e) {
/**
* 服務有異常
*/
request
return mapping
}
如下是解析XML文件變換成一個序列化的對象的JAVA代碼
/**
* 讀取XML文件所有信息
*/
public static Vector LoadXML(String path) throws Exception {
Vector xmlVector = null;
FileInputStream fi = null;
try {
fi = new FileInputStream(path);
xmlVector = new Vector();
SAXBuilder sb = new SAXBuilder();
Document doc = sb
Element root = doc
List focs = root
Element foc = null;
FocBean xml = null;
/**
* 從
*/
for (int i =
xml = new FocBean();
foc = (Element) focs
/* xml
xml
xml
xml
xml
xml
xml
xml
xml
/**
* 如下是最新版本的取得實體對象的方法
* modify by heweiya
*/
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xml
xmlVector
}
} catch (Exception e) {
System
} finally {
try {
fi
} catch (Exception e) {
e
}
}
return xmlVector;
}
還有一個代碼如下
java 代碼
// 把String 保存為文件
public static void saveXMLString(String XMLString
throws IOException {
File file = new File(fileName);
if (file
file
}
file
if (file
FileWriter fileOut = new FileWriter(file);
fileOut
fileOut
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26845.html