I have to write a C# class to convert the below XML with name simplexml
<Sample_Class3 xmlns="http://AvidUtility.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <USER_ID_MODIFIED> <ACTIVE_IND>Y</ACTIVE_IND> <CUSTOMER_ID>59</CUSTOMER_ID> <DATE_CREATED>2000-08-13T11:58:59</DATE_CREATED> <EMAIL>email@email.com</EMAIL> <FIRST_NAME>SYSTEM</FIRST_NAME> <JOB_TITLE/> <LAST_NAME>ADMINISTRATOR</LAST_NAME> <MIDDLE_INITIAL/> <PASSWORD>p2wd1234</PASSWORD> <PHONE_COUNTRY_CODE/> <PHONE_EXTENSION/> <PHONE_NUMBER>0</PHONE_NUMBER> <USER_ID>137</USER_ID> <USER_NAME>ADMINISTRATOR</USER_NAME> <USER_NAME_CREATED>system!administrator</USER_NAME_CREATED> </USER_ID_MODIFIED> <DATE_CLEARED>2001-08-13T11:58:59</DATE_CLEARED> </Sample_Class3> I am using the below method to execute the XML mapping to C# object.
public void ConvertBillAccountHistoryXMLtoObject3() { DataContractSerializer dcs = new DataContractSerializer(typeof(Sample_Class3)); string xmlpath = @"C:\Users\simplexml.xml"; FileStream fs = new FileStream(xmlpath, FileMode.Open); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); CommonAvidUtilityUrjanet.Sample_Class3 bah = (Sample_Class3)dcs.ReadObject(reader); reader.Close(); fs.Close(); } After running the code, I am not able to see the value for member DATE_CLEARED in Sample_Class3 object even though XML is having the value. However, if I keep xml tag at first place i.e. before XML tag, I am able to see the value populated for the same data member of object. Can some one please research and help me to understand as why DATE_CLEARED xml tag's value is not mapped to c# object if it is kept after XML tag?
No comments:
Post a Comment