场景一:提取SAML2报文
SAML2报文内容如下,从中提取对应的attribute name和value.
<saml:AttributeStatement>
<saml:Attribute Name="mail">
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">zhengkai.blog.csdn.net</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="cn">
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">amAdmin</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
show time
public static void main(String[] args) {
String content = "";
content = "<saml:AttributeStatement>";
content += " <saml:Attribute Name=\"mail\">";
content += " <saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">zhengkai.blog.youkuaiyun.com</saml:AttributeValue>";
content += " </saml:Attribute>";
content += " <saml:Attribute Name=\"cn\">";
content += " <saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">amAdmin</saml:AttributeValue>";
content += " </saml:Attribute>";
content += "</saml:AttributeStatement>";
String pattern = "\\<saml\\:Attribute Name=\\\"(?<scope>.*?)\\\"\\>[\\s\\S]*?\\<saml\\:AttributeValue[\\s\\S]*?\\>(?<value>.*?)\\<\\/saml\\:AttributeValue\\>[\\s\\S]*?\\<\\/saml\\:Attribute\\>";
Pattern r = Pattern.