Xml.cs 4.1 KB

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