java解析xml字符串


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]);
}
}
}
阅读更多
文章标签: XML Java
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭