Xml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Xml
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 75%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.IO;
  15. using System.Xml;
  16. using System.Xml.Xsl;
  17. using System.Xml.XPath;
  18. using System.Web;
  19. using System.Web.UI;
  20. namespace System.Web.UI.WebControls
  21. {
  22. [PersistChildren(false)]
  23. public class Xml : Control
  24. {
  25. private XmlDocument document;
  26. private string documentContent;
  27. private string documentSource;
  28. private XslTransform transform;
  29. private XsltArgumentList transformArgumentList;
  30. private string transformSource;
  31. private XPathDocument xpathDoc;
  32. private static XslTransform defaultTransform;
  33. static Xml()
  34. {
  35. XmlTextReader reader = new XmlTextReader(new StringReader("<xsl:stylesheet version='1.0' " +
  36. "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
  37. "<xsl:template match=\"\">" +
  38. "<xsl:copy-of select=\".\"/>" +
  39. "</xsl:template>" +
  40. "</xsl:stylesheet>"));
  41. defaultTransform = new XslTransform();
  42. defaultTransform.Load(reader);
  43. }
  44. public Xml(): base()
  45. {
  46. }
  47. [MonoTODO("Initialize_Document")]
  48. private void LoadXmlDoc()
  49. {
  50. throw new NotImplementedException();
  51. }
  52. public XmlDocument Document
  53. {
  54. get
  55. {
  56. if(document == null)
  57. LoadXmlDoc();
  58. return document;
  59. }
  60. set
  61. {
  62. documentSource = null;
  63. documentContent = null;
  64. xpathDoc = null;
  65. document = value;
  66. }
  67. }
  68. public string DocumentContent
  69. {
  70. get
  71. {
  72. return String.Empty;
  73. }
  74. set
  75. {
  76. document = null;
  77. xpathDoc = null;
  78. documentContent = value;
  79. }
  80. }
  81. public string DocumentSource
  82. {
  83. get
  84. {
  85. if(documentSource != null)
  86. return documentSource;
  87. return String.Empty;
  88. }
  89. set
  90. {
  91. document = null;
  92. documentContent = null;
  93. xpathDoc = null;
  94. documentSource = value;
  95. }
  96. }
  97. public XslTransform Transform
  98. {
  99. get
  100. {
  101. return transform;
  102. }
  103. set
  104. {
  105. transformSource = null;
  106. transform = value;
  107. }
  108. }
  109. public string TransformSource
  110. {
  111. get
  112. {
  113. if(transformSource != null)
  114. return transformSource;
  115. return String.Empty;
  116. }
  117. set
  118. {
  119. transform = null;
  120. transformSource = value;
  121. }
  122. }
  123. public XsltArgumentList TransformArgumentList
  124. {
  125. get
  126. {
  127. return transformArgumentList;
  128. }
  129. set
  130. {
  131. transformArgumentList = value;
  132. }
  133. }
  134. protected override void AddParsedSubObject(object obj)
  135. {
  136. if(obj is LiteralControl)
  137. {
  138. DocumentContent = ((LiteralControl)obj).Text;
  139. return;
  140. }
  141. throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_of_Type", "Xml", GetType().Name.ToString()));
  142. }
  143. [MonoTODO("Initialize_xpathDocument")]
  144. private void LoadXpathDoc()
  145. {
  146. if(documentContent != null && documentContent.Length > 0)
  147. {
  148. xpathDoc = new XPathDocument(new StringReader(documentContent));
  149. return;
  150. }
  151. if(documentSource == null || documentSource.Length == 0)
  152. {
  153. return;
  154. }
  155. throw new NotImplementedException();
  156. }
  157. [MonoTODO("Initialize_Transform")]
  158. private void LoadTransform()
  159. {
  160. throw new ArgumentException();
  161. }
  162. [MonoTODO]
  163. protected override void Render(HtmlTextWriter output)
  164. {
  165. if(document == null)
  166. {
  167. LoadXpathDoc();
  168. }
  169. LoadTransform();
  170. if(document == null || xpathDoc == null)
  171. {
  172. return;
  173. }
  174. if(transform == null)
  175. {
  176. transform = defaultTransform;
  177. }
  178. if(document != null)
  179. {
  180. Transform.Transform(document, transformArgumentList, output);
  181. return;
  182. }
  183. Transform.Transform(xpathDoc, transformArgumentList, output);
  184. }
  185. }
  186. }