fork download
  1. using System;
  2. using System.Xml;
  3. using System.Xml.Serialization;
  4. using System.Collections.Generic;
  5. using System.IO;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var xml = @"
  12. <Contracts>
  13. <Contract EntryType=""U"" ID=""401"" GroupCode=""1"">
  14. </Contract>
  15. </Contracts>
  16. ";
  17.  
  18. //Create our own namespaces for the output
  19. XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
  20.  
  21. //Add an empty namespace and empty value
  22. ns.Add("", "");
  23.  
  24. var sr = new StringReader(xml);
  25. var xr = new XmlTextReader(sr);
  26. var ser = new XmlSerializer(typeof(ContractPosting));
  27. var result = (ContractPosting)ser.Deserialize(xr);
  28.  
  29. foreach(var contract in result.Contracts)
  30. Console.WriteLine("(" + contract.EntryType + ", " +
  31. contract.ID + ", " + contract.GroupCode + ")");
  32. }
  33. }
  34.  
  35. // Define other methods and classes here
  36. [XmlRoot("Contracts")]
  37. public class ContractPosting {
  38. [XmlElement("Contract", typeof(Contract))]
  39. public List<Contract> Contracts { get; set; }
  40. }
  41.  
  42. public class Contract {
  43. [XmlAttribute("EntryType")]
  44. public string EntryType { get; set; }
  45. [XmlAttribute("ID")]
  46. public int ID { get; set; }
  47. [XmlAttribute("GroupCode")]
  48. public int GroupCode { get; set; }
  49. }
Success #stdin #stdout 0.22s 40848KB
stdin
Standard input is empty
stdout
(U, 401, 1)