我有一个xml响应,我希望从该xml响应中提取该XML的Saml Token内容,但内容嵌套在xsi:type =“ xsd:string”>下,我无法提取
我在xpath表达式下面写了 // * [local-name()='ExecuteAuthnRequestResult'] 但是它在ExecuteAuthnRequestResult标签下提供了所有内容,我只需要SamlToken
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ExecuteAuthnRequestResponse xmlns="http://www.wirds.com/Service/2013-03">
<ExecuteAuthnRequestResult><samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_b9d65dd5-b666-49b4-a625-c84a075f387d" InResponseTo="_4ed957f1-88bf-44e3-35f9-454d535fa420" Version="2.0" IssueInstant="2019-06-20T21:45:10.4188342Z" Destination="SamlWidget"><saml:Issuer AllowCreate="false" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">IdP</saml:Issuer><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></samlp:Status><saml:Assertion Version="2.0" ID="_dfc602fd-43a2-4d4f-81f0-1fefd4f5ce15" IssueInstant="2019-06-20T21:45:10.4188342Z" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><saml:Issuer AllowCreate="false">IdP</saml:Issuer><saml:Subject><saml:NameID AllowCreate="false" NameQualifier="Wizards">SamlAdapter</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData /></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2019-06-20T21:45:10.4188342Z" NotOnOrAfter="2019-06-20T21:50:10.4188342Z"><saml:AudienceRestriction /></saml:Conditions><saml:AuthnStatement AuthnInstant="2019-06-20T21:45:10.4188342Z"><saml:AuthnContext><saml:AuthnContextClassRef>saml:AuthnContextClassRef</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute Name="SamlToken" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"><saml:AttributeValue xsi:type="xsd:string">6tFbq4NmcX7vvh7IPDgNcbQZHvipXqPo0mENVrI+bl4PCcrOWu9fZE9OBmDv7KobVcCHGtVCvSIYI6clhkoe7xk61awPtyTQ+MFWYi+ebO1w/spiu7DJn+2DCKm9FbghHo2RP7MLiwUDHM772r3kcZ70zLhQnH2SoqZygy7I9XfZOcWtFN2nG7GoPcXwcLUvPu+iue6w91EhepcV7IVkYF40H+ft1VZ4Nv5BYpWQz8qqAa3StImYMHS1t8mSSvZtQ5QsJJgSSxbsrVX1EO5F9Ge4CaFhTKB/ux3cS81480+nh+6cMk+FGMlENhWK2xBdkPt89DJHl7h5DeBknX95Nnm8QPnlinTosVadLjjS187zVs0F+oyBnihgAfLXDYejAXbGuCXQgVHJWS4k/ZA8NSt7wTEJkoQodjYg5sTQOcW+YsAVowjA2YPEDkoJ0AWMzyRPwoebwrDrErCqG8LB4IHeQtY44ym2Elg0zdwCjrkHL/tuiVnp+DoTPXxqtUDOPZ2TaqGChVcX4PcV9FiG+AzA7QeIgwyYC+mxZghlEDLnkXp006tqV4Zpb1zJ5eAP5dfWbOCxKL6flNt2pkT/bbVwdxLqJFhcrfiOiwQTEsbHLloyw011esOvZ2d1FXsp</saml:AttributeValue></saml:Attribute><saml:Attribute Name="ScreenName" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"><saml:AttributeValue xsi:nil="true" /></saml:Attribute><saml:Attribute Name="ExpirationDate" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"><saml:AttributeValue xsi:type="xsd:string">06/21/2019 04:45:40</saml:AttributeValue></saml:Attribute><saml:Attribute Name="Permissions" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"><saml:AttributeValue xsi:type="xsd:string">&lt;ArrayOfString xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"&gt;
&lt;string&gt;LOGIN&lt;/string&gt;
&lt;string&gt;T&amp;amp;C&lt;/string&gt;
&lt;/ArrayOfString&gt;</saml:AttributeValue></saml:Attribute></saml:AttributeStatement><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI="#_dfc602fd-43a2-4d4f-81f0-1fefd4f5ce15"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>TeClTVB9KvGl6zdBwsH6TChyBNQ=</DigestValue></Reference></SignedInfo><SignatureValue>zczmd+bJb8kzM35RJ9FRx3+dx4vTMYpSoSqNCXKIJV5I4TBbCmc6H8U44bLl4ziudS9eVRiyF4hpRU2SaaB472Sz1trqI3PmEzU/6Dw8qveLq9uya+KHR8SyFMBeRp6DgC24TQe8HweuEBxAfFYVcwJvpXBZs1Sh/ehp+T4tvhN6LepahARS4cZQ3uJpyaXiT8HEMacXYdhtlGtgM4+Fri/Eq+peSkBe8cEp0wdwYJFAMe7RAR3Wl6tZhRjoYVjzCBbBF4570BNIt4TQ+if5JjI9KLEW1Otp/6HozGhuNxzjhqExACj13EkNLPC5twL5X2cUOTKlJm1aiu4mIN+C0A==</SignatureValue></Signature></saml:Assertion><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>gP6oqV97oj000S/5G87Ub96VbMw=</DigestValue></Reference></SignedInfo><SignatureValue>hsgE/FHSKm32OYBMfu8ruUZVh+IGF4MVsOi5AqsxkRTT2NXMo4J45sjypxA8mFdAF9ULtxHqAv1O+HMKRD4wLiENXQjPyMOx2Ar3rLxxZIBTbJpUhbZorVt/4/Ifd26D5OjNtJ1p3gCMkwi72RGRKXtuyj1hrkpZ8gUTV+DC7cc=</SignatureValue></Signature></samlp:Response>
</ExecuteAuthnRequestResult>
</ExecuteAuthnRequestResponse>
</s:Body>
</s:Envelope>
我希望从此xml中提取Saml Token内容,但是内容嵌套在xsi:type =“ xsd:string”>下,我无法提取
答案 0 :(得分:0)
我知道这个xpath更大。
因此,基本上,您必须使用substring-berfore
和substring-after
获取令牌字符串。下面是xpath
substring-before(substring-after(//*[local-name() = 'ExecuteAuthnRequestResult'] /text(),'<saml:AttributeValue xsi:type="xsd:string">'),'</saml:AttributeValue>')
屏幕截图:
输出:
'6tFbq4NmcX7vvh7IPDgNcbQZHvipXqPo0mENVrI + bl4PCcrOWu9fZE9OBmDv7KobVcCHGtVCvSIYI6clhkoe7xk61awPtyTQ + MFWYi + ebO1w / spiu7DJn + 2DCKm9FbghHo2RP7MLiwUDHM772r3kcZ70zLhQnH2SoqZygy7I9XfZOcWtFN2nG7GoPcXwcLUvPu + iue6w91EhepcV7IVkYF40H + ft1VZ4Nv5BYpWQz8qqAa3StImYMHS1t8mSSvZtQ5QsJJgSSxbsrVX1EO5F9Ge4CaFhTKB / ux3cS81480 + NH + 6cMk + FGMlENhWK2xBdkPt89DJHl7h5DeBknX95Nnm8QPnlinTosVadLjjS187zVs0F + oyBnihgAfLXDYejAXbGuCXQgVHJWS4k / ZA8NSt7wTEJkoQodjYg5sTQOcW + YsAVowjA2YPEDkoJ0AWMzyRPwoebwrDrErCqG8LB4IHeQtY44ym2Elg0zdwCjrkHL / tuiVnp + DoTPXxqtUDOPZ2TaqGChVcX4PcV9FiG + AzA7QeIgwyYC + mxZghlEDLnkXp006tqV4Zpb1zJ5eAP5dfWbOCxKL6flNt2pkT / bbVwdxLqJFhcrfiOiwQTEsbHLloyw011esOvZ2d1FXsp'