报文发送解析xml
Posted xjatj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了报文发送解析xml相关的知识,希望对你有一定的参考价值。
1 FtpBasicRequestForMany ftpBasicRequestForMany = new FtpBasicRequestForMany(); 2 FtpPackRequestForMany ftpPackRequestForMany = new FtpPackRequestForMany(); 3 FtpParamsForMany ftpParamsForMany = new FtpParamsForMany(); 4 ftpParamsForMany.setFileName(fileName); 5 ftpParamsForMany.setFtpServerIP(ftpIp); 6 ftpParamsForMany.setFtpServerPort(Integer.valueOf(ftpPort.trim())); 7 ftpParamsForMany.setFtpServerUserName(ftpUserName); 8 ftpParamsForMany.setFtpServerUserPwd(ftpPsd); 9 ftpPackRequestForMany.setCommandType(EncoderRequestEnum.REQUEST.code()); 10 ftpPackRequestForMany.setCommand(EncoderRequestEnum.UPDATE.code()); 11 12 13 ftpPackRequestForMany.setFtpParamsForMany(ftpParamsForMany); 14 ftpBasicRequestForMany.setFtpPackRequestForMany(ftpPackRequestForMany); 15 16 17 18 @XmlAccessorType(XmlAccessType.FIELD) 19 @XmlRootElement(name = "Message") 20 public class FtpBasicRequestForMany implements Cloneable { 21 /** 22 * 23 */ 24 @XmlElement(name = "DevIndexCode") 25 private String devIndexCode; 26 /** 27 * 28 */ 29 @XmlElement(name = "Pack") 30 private FtpPackRequestForMany ftpPackRequestForMany; 31 32 /** 33 * 获取devIndexCode 34 * 35 * @return devIndexCode devIndexCode 36 */ 37 public String getDevIndexCode() { 38 return devIndexCode; 39 40 } 41 42 /** 43 * 设置devIndexCode 44 * 45 * @param devIndexCode 46 * devIndexCode 47 */ 48 public void setDevIndexCode(String devIndexCode) { 49 this.devIndexCode = devIndexCode; 50 } 51 52 public FtpPackRequestForMany getFtpPackRequestForMany() { 53 return ftpPackRequestForMany; 54 } 55 56 public void setFtpPackRequestForMany(FtpPackRequestForMany ftpPackRequestForMany) { 57 this.ftpPackRequestForMany = ftpPackRequestForMany; 58 } 59 60 @Override 61 public FtpBasicRequestForMany clone() throws CloneNotSupportedException { 62 FtpBasicRequestForMany clone = (FtpBasicRequestForMany) super.clone(); 63 clone.ftpPackRequestForMany = this.ftpPackRequestForMany.clone(); 64 return clone; 65 } 66 } 67 68 69 @XmlAccessorType(XmlAccessType.FIELD) 70 public class FtpPackRequestForMany implements Cloneable { 71 /** 72 * 73 */ 74 @XmlAttribute 75 private String type = "PAG"; 76 /** 77 * 78 */ 79 @XmlElement(name = "Version") 80 private String version = "1.0"; 81 /** 82 * 83 */ 84 @XmlElement(name = "Sequence") 85 private String sequence = "1"; 86 /** 87 * 88 */ 89 @XmlElement(name = "CommandType") 90 private String commandType; 91 /** 92 * 93 */ 94 @XmlElement(name = "Command") 95 private String command; 96 /** 97 * 98 */ 99 @XmlElement(name = "Params") 100 private FtpParamsForMany ftpParamsForMany; 101 102 public String getType() { 103 return type; 104 } 105 106 public void setType(String type) { 107 this.type = type; 108 } 109 110 public String getVersion() { 111 return version; 112 } 113 114 public void setVersion(String version) { 115 this.version = version; 116 } 117 118 public String getSequence() { 119 return sequence; 120 } 121 122 public void setSequence(String sequence) { 123 this.sequence = sequence; 124 } 125 126 public String getCommandType() { 127 return commandType; 128 } 129 130 public void setCommandType(String commandType) { 131 this.commandType = commandType; 132 } 133 134 public String getCommand() { 135 return command; 136 } 137 138 public void setCommand(String command) { 139 this.command = command; 140 } 141 142 public FtpParamsForMany getFtpParamsForMany() { 143 return ftpParamsForMany; 144 } 145 146 public void setFtpParamsForMany(FtpParamsForMany ftpParamsForMany) { 147 this.ftpParamsForMany = ftpParamsForMany; 148 } 149 150 @Override 151 protected FtpPackRequestForMany clone() throws CloneNotSupportedException { 152 FtpPackRequestForMany clone = (FtpPackRequestForMany) super.clone(); 153 clone.ftpParamsForMany = this.ftpParamsForMany.clone(); 154 return clone; 155 } 156 } 157 protocolStr = XmlUtil.toXml(protocol); 158 159 解析 160 161 public static <T> T unMarshaller(Class<T> cls, String protocol) { 162 return unMarshaller(cls, protocol, "UTF-8"); 163 } 164 165 public static <T> T unMarshaller(Class<T> cls, String protocol, String code) { 166 T t = null; 167 ByteArrayInputStream is = null; 168 169 try { 170 is = new ByteArrayInputStream(protocol.getBytes(code)); 171 JAXBContext context = JAXBContext.newInstance(cls); 172 Unmarshaller unmarshaller = context.createUnmarshaller(); 173 t = unmarshaller.unmarshal(is); 174 } catch (Exception var14) { 175 throw new UnsupportedOperationException(var14); 176 } finally { 177 if (is != null) { 178 try { 179 is.close(); 180 } catch (IOException var13) { 181 throw new UnsupportedOperationException(var13); 182 } 183 } 184 185 } 186 187 return t; 188 } 189
以上是关于报文发送解析xml的主要内容,如果未能解决你的问题,请参考以下文章
PHP通过XML报文方式,已第三方接口交互(发送xml,获取XML,并解析xml步骤)