This is my xml generated for retrieving members of a group. I need to get the value tech\abc1234 from this xml.
<tcm:Trustee xlink:href="tcm:0-61-65552" xlink:type="simple" xlink:title="tech\abc1234" Type="65552" Icon="T65552L0P0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:Trustee>
But when i try to get the attribute value like:
XElement userList = csClient.GetListXml(grpId, members);
foreach (var eachuser in userList.Elements())
{
logdetails(eachuser.Attribute("xlink:title").Value.ToString());
}
I am getting the following error :
error The ':' character, hexadecimal value 0x3A, cannot be included in a name.
Currently, you're using the string to XName conversion, which takes that string as just the local ID of an element, and that can't contain a colon.
You need to create an XName with the full namespace + local ID. Fortunately, LINQ makes that really easy:
XNamespace xlink = "http://www.w3.org/1999/xlink";
XElement userList = csClient.GetListXml(grpId, members);
foreach (var user in userList.Elements())
{
logdetails(user.Attribute(xlink + "title").Value);
}
Note that there's no need to call ToString() after Value - XAttribute.Value already returns a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With