1
0

XmlRpcResponseDeserializer.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. namespace Nwc.XmlRpc
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.IO;
  6. using System.Xml;
  7. /// <summary>Class to deserialize XML data representing a response.</summary>
  8. public class XmlRpcResponseDeserializer : XmlRpcDeserializer
  9. {
  10. static private XmlRpcResponseDeserializer _singleton;
  11. /// <summary>A static singleton instance of this deserializer.</summary>
  12. [Obsolete("This object is now thread safe, just use an instance.", false)]
  13. static public XmlRpcResponseDeserializer Singleton
  14. {
  15. get
  16. {
  17. if (_singleton == null)
  18. _singleton = new XmlRpcResponseDeserializer();
  19. return _singleton;
  20. }
  21. }
  22. /// <summary>Static method that parses XML data into a response using the Singleton.</summary>
  23. /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC response.</param>
  24. /// <returns><c>XmlRpcResponse</c> object resulting from the parse.</returns>
  25. override public Object Deserialize(TextReader xmlData)
  26. {
  27. XmlTextReader reader = new XmlTextReader(xmlData);
  28. XmlRpcResponse response = new XmlRpcResponse();
  29. bool done = false;
  30. lock (this)
  31. {
  32. Reset();
  33. while (!done && reader.Read())
  34. {
  35. DeserializeNode(reader); // Parent parse...
  36. switch (reader.NodeType)
  37. {
  38. case XmlNodeType.EndElement:
  39. switch (reader.Name)
  40. {
  41. case FAULT:
  42. response.Value = _value;
  43. response.IsFault = true;
  44. break;
  45. case PARAM:
  46. response.Value = _value;
  47. _value = null;
  48. _text = null;
  49. break;
  50. }
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. }
  57. return response;
  58. }
  59. }
  60. }