package fax.util;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.apache.commons.lang.StringUtils;
import net.coobird.thumbnailator.Thumbnails;
//XML解析文件
public class Test {
private String endPoint;
private String AspId; //AP提供商编号
private String TradeCode;
String namespaceURI = "TradeService";
Document document = null;
public String errInfo = "";
public String succInfo = "";
String paraSerial = "serial";//序号
String paraRand = "rand";//随机码
String paraEncode = "encode";//hashcode
/**** * 根据传进去的节点名,返回该节点的值 * @param nodeName * @return * @throws Exception */
public String getSingleNodeValue(String nodeName) throws Exception {
String ret = "";
NodeList nodeList = document.getElementsByTagName(nodeName);
if (nodeList.item(0) == null) {
// throw new Exception("Can't find node!" + nodeName);
System.out.println("Can't find node!" + nodeName);
return "";
}
if (nodeList.item(0).getFirstChild() != null) {
ret = nodeList.item(0).getFirstChild().getNodeValue().trim();
}
return ret;
}
/**** * 把一个字符串转成XML类型 * @param content * @throws Exception */
public void loadXml(String content) throws Exception {
InputStream is = new ByteArrayInputStream(content.getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(is);
}
/**** * 调用远程接口并获得返回的值 * @param endPoint * @param namespaceURI * @param localPart * @param args * @return */
public String getWebServiceResult(String endPoint,String namespaceURI,String localPart,Object[] args) {
String ret = null;
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endPoint));
call.setoperationName(new QName(namespaceURI,localPart));
ret = (String) call.invoke(args);
} catch (Exception e) {
}
return ret;
}
/**** * 对所有功能进行操作 * @param areaid * @param EpId * @param Account * @param Pwd * @return */
public String checkAccountPwd(String endPoint,String Name,String Account,String Pwd) {
// endPoint="http://192.168.0.110:8080/ZZweb/ProductPurchaseImpl.jws";
/*** * 第一个参数和第二个是连接地址,第三个是方法名,最后个是参数。 */
String resultXml = this.getWebServiceResult(endPoint,endPoint,Name,new Object[] { "" });
System.out.println(resultXml);
try {
this.loadXml(resultXml);
} catch (Exception e) {
// this.printErrorMsg("数据传送出错!");
}
String retunstatus = "";
String usertype = "";
try {
retunstatus = this.getSingleNodeValue(Pwd);
} catch (Exception e) {
e.printstacktrace();
}
return retunstatus;
}
/** * 获取节点内容 * @description * @param stringxml * @param key * @return */
public String check(String stringxml,String key) throws Exception {
this.loadXml(stringxml);
String retunstatus = "";
retunstatus = this.getSingleNodeValue(key);
return retunstatus;
}
}
原文地址:https://www.jb51.cc/xml/297163.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。