在Java8中使用名称空间读取Soap响应
我想阅读AccountNumber、OrderNumber、responseCode和responseDescription。我能够使用在Java8中使用名称空间读取Soap响应,soap,java-8,Soap,Java 8,我想阅读AccountNumber、OrderNumber、responseCode和responseDescription。我能够使用 公共静态字符串getTagContents(字符串xmlString,字符串标记名){ 字符串resp=“”; 字符串bTagName=“”; int stInd=xmlString.indexOf(bTagName); int enId=xmlString.indexOf(“”); 如果(stInd>-1&&ENID>-1){ resp=xmlString.
公共静态字符串getTagContents(字符串xmlString,字符串标记名){
字符串resp=“”;
字符串bTagName=“”;
int stInd=xmlString.indexOf(bTagName);
int enId=xmlString.indexOf(“”);
如果(stInd>-1&&ENID>-1){
resp=xmlString.substring(stInd+bTagName.length(),enId);
}
返回响应;
}
同样,responseCode和responseDescription也失败了
45300895
00
成功
因为您要在标记处查找精确的字符串值。代码将用于AccountNumber,因为标记没有附加值。另一方面,responseCode标记的精确字符串值如下:
<responseCode xmlns="http://www.someurl.com">
我相信你绝对应该使用像这样的公共图书馆
如果您确实想使用自己的代码,可以应用此解决方案:
public static String getTagContents(String xmlString, String tagName) {
String resp = "";
String bTagName = "<" + tagName;
int stInd = xmlString.indexOf(bTagName);
int enInd = xmlString.indexOf("</" + tagName);
if (stInd > -1 && enInd > -1) {
resp = xmlString.substring(stInd + bTagName.length(), enInd);
}
return resp.split(">")[1];
}
公共静态字符串getTagContents(字符串xmlString,字符串标记名){
字符串resp=“”;
字符串bTagName=“”)[1];
}
因为您要在标记处查找精确的字符串值。代码将用于AccountNumber,因为标记没有附加值。另一方面,responseCode标记的精确字符串值如下:
<responseCode xmlns="http://www.someurl.com">
我相信你绝对应该使用像这样的公共图书馆
如果您确实想使用自己的代码,可以应用此解决方案:
public static String getTagContents(String xmlString, String tagName) {
String resp = "";
String bTagName = "<" + tagName;
int stInd = xmlString.indexOf(bTagName);
int enInd = xmlString.indexOf("</" + tagName);
if (stInd > -1 && enInd > -1) {
resp = xmlString.substring(stInd + bTagName.length(), enInd);
}
return resp.split(">")[1];
}
公共静态字符串getTagContents(字符串xmlString,字符串标记名){
字符串resp=“”;
字符串bTagName=“”)[1];
}