The ':' character, cannot be included in an attribute name [duplicate]




This question already has an answer here:




Quick question. I am having a lot of problems trying to get attributes out of the exerp of my xml document.



<Data Key="SS_JESSS" ic:StudySubjectID="JessSmith" ic:Status="available" ic:Sex="m" ic:EnrollmentDate="2014-09-04">
<EventData EventOID="SE_INITIALVISIT" ic:StartDate="2014-10-13 00:00:00.0" ic:Status="data entry started" StudyEventRepeatKey="1">
<Data....>
<EventData....>


I have tried something ismple as shown below. In the code occ is the Xnamespace. Also as you can see i'm putting these into a datatable.



var datasubject = data_ic.Descendants(occ + "SubjectData");

foreach (var item in datasubject)
{
row["ic:Sex"] = item.Attribute(ic:Sex").Value;

}


This throws up a " The ':' character, hexadecimal value 0x3A, cannot be included in a name" error. i also tried



row["ic:Sex"] = item.Attribute("Key").NextAttribute.NextAttribute.NextAttribute.Value;


However this does not work all the time as an extra attribute exist if an execption occurs shown below.



<Data Key="SS_TESTB_7448" ic:StudySubjectID="TestBot" ic:Status="available" ic:SecondaryID="12344" ic:Sex="m" ic:EnrollmentDate="2014-11-04">


Thank you for all your help. Cheers.


No comments:

Post a Comment