public static String[] parseString() {
String[] strArr = new String[4];
//特定的xml格式字符串
String str = "<ReturnValue><state>状态值</state><CommandID>CommandID</CommandID>" +
"<MsgSubSeq>MsgSubSeq</MsgSubSeq><Description>描述</Description>" +
"</ReturnValue>";
String state = str.substring(str.indexOf("<state>")+7,str.indexOf("</state>"));
String commandID = str.substring(str.indexOf("<CommandID>")+11,str.indexOf("</CommandID>"));
String msgSubSeq = str.substring(str.indexOf("<MsgSubSeq>")+11,str.indexOf("</MsgSubSeq>"));
String description = str.substring(str.indexOf("<Description>")+13,str.indexOf("</Description>"));
strArr[0] = state;
strArr[1] = commandID;
strArr[2] = msgSubSeq;
strArr[3] = description;
return strArr;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] strArr = parseString();
if(strArr != null && strArr.length > 1) {
for(int loop = 0; loop < strArr.length; loop++) {
System.out.println("strArr["+loop+"]==>"+strArr[loop]);
}
}
}
java解析xml字符串
最新推荐文章于 2024-08-12 23:01:19 发布