1
0

XmlRpcResponseSerializer.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace Nwc.XmlRpc
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Xml;
  6. /// <summary>Class responsible for serializing an XML-RPC response.</summary>
  7. /// <remarks>This class handles the response envelope, depending on XmlRpcSerializer
  8. /// to serialize the payload.</remarks>
  9. /// <seealso cref="XmlRpcSerializer"/>
  10. public class XmlRpcResponseSerializer : XmlRpcSerializer
  11. {
  12. static private XmlRpcResponseSerializer _singleton;
  13. /// <summary>A static singleton instance of this deserializer.</summary>
  14. static public XmlRpcResponseSerializer Singleton
  15. {
  16. get
  17. {
  18. if (_singleton == null)
  19. _singleton = new XmlRpcResponseSerializer();
  20. return _singleton;
  21. }
  22. }
  23. /// <summary>Serialize the <c>XmlRpcResponse</c> to the output stream.</summary>
  24. /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
  25. /// <param name="obj">An <c>Object</c> to serialize.</param>
  26. /// <seealso cref="XmlRpcResponse"/>
  27. override public void Serialize(XmlTextWriter output, Object obj)
  28. {
  29. XmlRpcResponse response = (XmlRpcResponse)obj;
  30. output.WriteStartDocument();
  31. output.WriteStartElement(METHOD_RESPONSE);
  32. if (response.IsFault)
  33. output.WriteStartElement(FAULT);
  34. else
  35. {
  36. output.WriteStartElement(PARAMS);
  37. output.WriteStartElement(PARAM);
  38. }
  39. output.WriteStartElement(VALUE);
  40. SerializeObject(output, response.Value);
  41. output.WriteEndElement();
  42. output.WriteEndElement();
  43. if (!response.IsFault)
  44. output.WriteEndElement();
  45. output.WriteEndElement();
  46. }
  47. }
  48. }