2 // System.Web.UI.WebControls.Xml.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 // (C) Gaurav Vaish (2002)
11 // (C) 2003 Andreas Nahr
15 using System.ComponentModel;
16 using System.ComponentModel.Design;
20 using System.Xml.XPath;
24 namespace System.Web.UI.WebControls
26 [DefaultProperty("DocumentSource")]
27 [PersistChildren(false)]
28 [ControlBuilder (typeof (XmlBuilder))]
29 [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
30 public class Xml : Control
32 static XslTransform defaultTransform;
35 string documentContent;
36 string documentSource;
37 XslTransform transform;
38 XsltArgumentList transformArgumentList;
39 string transformSource;
40 XPathDocument xpathDoc;
44 XmlTextReader reader = new XmlTextReader (new StringReader("<xsl:stylesheet version='1.0' " +
45 "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
46 "<xsl:template match=\"*\">" +
47 "<xsl:copy-of select=\".\"/>" +
49 "</xsl:stylesheet>"));
51 defaultTransform = new XslTransform();
53 defaultTransform.Load (reader);
55 defaultTransform.Load (reader, null, null);
63 [MonoTODO("security")]
64 private void LoadXmlDoc ()
66 if (documentContent != null && documentContent.Length > 0) {
67 document = new XmlDocument ();
68 document.LoadXml (documentContent);
72 if (documentSource != null && documentSource.Length != 0) {
73 document = new XmlDocument ();
74 document.Load (documentSource);
78 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 [WebSysDescription ("This is the XML document that is used for the XML Webcontrol.")]
80 public XmlDocument Document {
87 documentSource = null;
88 documentContent = null;
94 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
95 [WebSysDescription ("The XML content that is transformed for the XML Webcontrol.")]
96 public string DocumentContent {
103 documentContent = value;
107 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
108 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
109 [WebSysDescription ("The URL or the source of the XML content that is transformed for the XML Webcontrol.")]
110 public string DocumentSource {
112 if (documentSource != null)
113 return documentSource;
118 documentContent = null;
120 documentSource = value;
124 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
125 [WebSysDescription ("The XSL transform that is applied to this XML Webcontrol.")]
126 public XslTransform Transform {
131 transformSource = null;
136 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
137 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
138 [WebSysDescription ("An URL specifying the source that is used for the XSL transformation.")]
139 public string TransformSource {
141 if (transformSource != null)
142 return transformSource;
147 transformSource = value;
151 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
152 [WebSysDescription ("Arguments that are used by the XSL Transform.")]
153 public XsltArgumentList TransformArgumentList {
154 get { return transformArgumentList; }
155 set { transformArgumentList = value; }
158 protected override void AddParsedSubObject (object obj)
160 if (obj is LiteralControl) {
161 DocumentContent = ((LiteralControl) obj).Text;
165 throw new HttpException (HttpRuntime.FormatResourceString (
166 "Cannot_Have_Children_of_Type",
171 [MonoTODO("security")]
172 private void LoadXpathDoc ()
174 if (documentContent != null && documentContent.Length > 0) {
175 xpathDoc = new XPathDocument (new StringReader (documentContent));
179 if (documentSource != null && documentSource.Length != 0) {
180 xpathDoc = new XPathDocument (MapPathSecure (documentSource));
185 [MonoTODO("security")]
186 private void LoadTransform ()
188 if (transform != null)
191 if (transformSource != null && transformSource.Length != 0) {
192 transform = new XslTransform ();
193 transform.Load (MapPathSecure (transformSource));
197 protected override void Render(HtmlTextWriter output)
199 if (document == null) {
204 if (document == null && xpathDoc == null) {
208 if (transform == null) {
209 transform = defaultTransform;
212 if (document != null) {
214 Transform.Transform(document, transformArgumentList, output);
216 Transform.Transform(document, transformArgumentList, output, null);
221 Transform.Transform(xpathDoc, transformArgumentList, output);
223 Transform.Transform(xpathDoc, transformArgumentList, output, null);