Get XML Element with JDOM



I have a XML file like the following one.



<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Destination="http://ift.tt/1CoMB7U"
ID="id-OPIfhD3il2eK816THPlj2Nk38KM-"
IssueInstant="2014-09-02T14:36:02Z"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Version="2.0"
>
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
>http://ift.tt/1ukrizz;
<samlp:NameIDPolicy AllowCreate="true"
Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
/>
<samlp:RequestedAuthnContext Comparison="exact">
<saml:AuthnContextClassRef xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>


How can get the content "http://ift.tt/1CoMB7W" from the above XML using JDOM ?


I am trying the below code and able to retrieve the "IssueInstant" & "ProtocolBinding" successfully. But unable to retrieve the content "http://ift.tt/1CoMB7W". Please help.



private String[] getRequestAttributes(String xmlString) throws SamlException {
Document doc = Util.createJdomDoc(xmlString);
if (doc != null) {
String[] samlRequestAttributes = new String[2];
samlRequestAttributes[0] = doc.getRootElement().getAttributeValue(
"IssueInstant");
samlRequestAttributes[2] = doc.getRootElement().getAttributeValue(
"ProtocolBinding");
return samlRequestAttributes;
}
}

No comments:

Post a Comment