Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class Title
  2. {
  3. [XmlAttribute("id")]
  4. public int Id { get; set; }
  5.  
  6. public string Value { get; set; }
  7. }
  8.  
  9. <Title id="123">Some Title Value</Title>
  10.  
  11. public class Title
  12. {
  13. [XmlAttribute("id")]
  14. public int Id { get; set; }
  15.  
  16. [XmlText]
  17. public string Value { get; set; }
  18. }
  19.  
  20. <?xml version="1.0" encoding="utf-16"?>
  21. <Title xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  22. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  23. id="123"
  24. >Grand Poobah</Title>
  25.  
  26. using System;
  27. using System.IO;
  28. using System.Text;
  29. using System.Xml.Serialization;
  30.  
  31. namespace ConsoleApplication2
  32. {
  33. class Program
  34. {
  35. static void Main(string[] args)
  36. {
  37. var title = new Title() { Id = 3, Value = "something" };
  38. var serializer = new XmlSerializer(typeof(Title));
  39. var stream = new MemoryStream();
  40. serializer.Serialize(stream, title);
  41. stream.Flush();
  42. Console.Write(new string(Encoding.UTF8.GetChars(stream.GetBuffer())));
  43. Console.ReadLine();
  44. }
  45. }
  46.  
  47. public class Title
  48. {
  49. [XmlAttribute("id")]
  50. public int Id { get; set; }
  51. [XmlText]
  52. public string Value { get; set; }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement