Hakan Axheim

Hakan Axheim

  • NA
  • 201
  • 32.4k

Reading an XML file using DataContracts

Mar 5 2021 12:03 PM
Hi,
 
I am trying to DeSerialize this XML file with DataContracts.
  1. string xmlData = @"<?xml version='1.0' encoding='utf-8' standalone='yes'?>  
  2. <objects ResultsRemaining='0'>  
  3. <object><id>CF7E7B22-1D3A-4CFE-91F9-F8C5C2DB4069</id>  
  4. <parentid>ED98C97F-A202-48ED-AEEA-34362508A30B</parentid>  
  5. <name>NorthernLights</name>  
  6. <type>file</type>  
  7. <dateadded>1614924419</dateadded>  
  8. <permissions>  
  9. <read />  
  10. <write />  
  11. <saveanno />  
  12. <publishanno />  
  13. <viewrmeta />  
  14. <viewmacro />  
  15. <viewlabel />  
  16. <copyexport />  
  17. <share />  
  18. <downloadslide />  
  19. </permissions>  
  20. <content>  
  21. <file>  
  22. <filepath>68934805-fa78-4d84-aac1-fbcde4a7a8f2.png</filepath>  
  23. <mime>image/png</mime>  
  24. </file>  
  25. </content>  
  26. </object>  
  27. </objects>";  
I have created this structure with classes:
 
Objects -- Object -- Permission
Content --- File
 
I have no errors when I DeSerialize the XML data but no objects will be created.
 
My code is as follow;
  1. Objects objects = new Objects();  
  2. objects = dataCSUtility.DeSerializer<Objects>(xmlData);  
Nothing will be assigned to objects!
 
Can anybody solve this?

Answers (3)