I am trying to add values to the saml:AttributeValue elements of this xml document:
<saml:AttributeStatement xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<saml:Attribute Name="FNAME">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="LNAME">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="Gender">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="UniqueID">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="DateOfBirth">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="ClientID">
<saml:AttributeValue></saml:AttributeValue>
</saml:Attribute>
Using this c# code:
//get the AttributeStatement node
XmlNode attrs = assertion.SelectSingleNode("//saml:AttributeStatement", ns1);
//get the Attribute nodes within the AttributeStatement node
XmlNodeList attr = attrs.SelectNodes("//saml:Attribute", ns1);
//foreach node in the Attribute node list get the AttributeValue node and add an innerText value
foreach (XmlNode xn in attr)
{
XmlNode attrValue = xn.SelectSingleNode("//saml:AttributeValue", ns1);
switch (xn.Attributes["Name"].Value)
{
case "FNAME":
attrValue.InnerText = UserInfo.FirstName;
break;
case "LNAME":
attrValue.InnerText = UserInfo.LastName;
break;
case "Gender":
attrValue.InnerText = UserInfo.Email;
break;
case "UniqueID":
attrValue.InnerText = UserInfo.UserID.ToString();
break;
case "DateOfBirth":
attrValue.InnerText = UserInfo.UserID.ToString();
break;
case "ClientID":
attrValue.InnerText = UserInfo.UserID.ToString();
break;
default:
attrValue.InnerText = "No attribute listed";
break;
}
//output each AttributeValue innerText.
lblTest.Text += attrValue.InnerText + " ";
}
The lblTest is displaying how I would expect - with the correct values for all 6 elements, but the document is not displaying any values at all. Is this the correct way to loop through and add these values to nodes?