String testStr="<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/>"
+"<SOAP-ENV:Body>"
+"<samlp:ArtifactResolve xmlns:samlp=urn:oasis:names:tc:SAML:2.0:protocol xmlns:saml=urn:oasis:names:tc:SAML:2.0:assertion ID=id_2 Version=2.0 IssueInstant=2007-12-05T09:22:04Z>"
+"<saml:Issuer>https://idm.10086.cn/SSO</saml:Issuer>"
+"<samlp:Artifact>e4fd0055e1e64077aadf39c98a2814a2</samlp:Artifact>"
+"</samlp:ArtifactResolve>"
+"</SOAP-ENV:Body>"
+"</SOAP-ENV:Envelope>";
截取<SOAP-ENV:Body>和</SOAP-ENV:Body>标签之间的内容,用java的正则表达式实现
在线等求解,急急急!
String testStr="<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/>"
+"<SOAP-ENV:Body>"
+"<samlp:ArtifactResolve xmlns:samlp=urn:oasis:names:tc:SAML:2.0:protocol xmlns:saml=urn:oasis:names:tc:SAML:2.0:assertion ID=id_2 Version=2.0 IssueInstant=2007-12-05T09:22:04Z>"
+"<saml:Issuer>https://idm.10086.cn/SSO</saml:Issuer>"
+"<samlp:Artifact>e4fd0055e1e64077aadf39c98a2814a2</samlp:Artifact>"
+"</samlp:ArtifactResolve>"
+"</SOAP-ENV:Body>"
+"</SOAP-ENV:Envelope>";
Pattern p = Pattern.compile("<SOAP-ENV:Body>(.*)</SOAP-ENV:Body>");
Matcher m = p.matcher(testStr);
while(m.find()){
System.out.println(m.group(1));
}
testStr = testStr.replaceAll("(?is).*?<SOAP-ENV:Body>(.*?)</SOAP-ENV:Body>.*", "$1");
System.out.println(testStr);