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;
\r
19 using System.Xml.Xsl;
\r
20 using System.Xml.XPath;
\r
22 using System.Web.UI;
\r
24 namespace System.Web.UI.WebControls
\r
26 [DefaultProperty("DocumentSource")]
\r
27 [PersistChildren(false)]
28 [ControlBuilder (typeof (XmlBuilder))]
29 [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
\r
30 public class Xml : Control
\r
32 private XmlDocument document;
\r
33 private string documentContent;
\r
34 private string documentSource;
\r
35 private XslTransform transform;
\r
36 private XsltArgumentList transformArgumentList;
\r
37 private string transformSource;
\r
39 private XPathDocument xpathDoc;
\r
41 private static XslTransform defaultTransform;
\r
45 XmlTextReader reader = new XmlTextReader(new StringReader("<xsl:stylesheet version='1.0' " +
\r
46 "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
\r
47 "<xsl:template match=\"*\">" +
\r
48 "<xsl:copy-of select=\".\"/>" +
\r
50 "</xsl:stylesheet>"));
\r
51 defaultTransform = new XslTransform();
\r
53 defaultTransform.Load (reader);
55 defaultTransform.Load (reader, null, null);
59 public Xml(): base()
\r
63 [MonoTODO("security")]
\r
64 private void LoadXmlDoc ()
\r
66 if (documentContent != null && documentContent.Length > 0) {
\r
67 document = new XmlDocument();
\r
68 document.LoadXml (documentContent);
\r
72 if (documentSource != null && documentSource.Length != 0) {
\r
73 document = new XmlDocument();
\r
74 document.Load (documentSource);
\r
78 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 [WebSysDescription ("This is the XML document that is used for the XML Webcontrol.")]
\r
80 public XmlDocument Document
\r
84 if(document == null)
\r
90 documentSource = null;
\r
91 documentContent = null;
\r
97 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
98 [WebSysDescription ("The XML content that is transformed for the XML Webcontrol.")]
\r
99 public string DocumentContent
\r
103 return String.Empty;
\r
109 documentContent = value;
\r
113 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
114 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
115 [WebSysDescription ("The URL or the source of the XML content that is transformed for the XML Webcontrol.")]
\r
116 public string DocumentSource
\r
120 if(documentSource != null)
\r
121 return documentSource;
\r
122 return String.Empty;
\r
127 documentContent = null;
\r
129 documentSource = value;
\r
133 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
134 [WebSysDescription ("The XSL transform that is applied to this XML Webcontrol.")]
\r
135 public XslTransform Transform
\r
143 transformSource = null;
\r
148 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
149 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
150 [WebSysDescription ("An URL specifying the source that is used for the XSL transformation.")]
\r
151 public string TransformSource
\r
155 if(transformSource != null)
\r
156 return transformSource;
\r
157 return String.Empty;
\r
162 transformSource = value;
\r
166 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
167 [WebSysDescription ("Arguments that are used by the XSL Transform.")]
\r
168 public XsltArgumentList TransformArgumentList
\r
172 return transformArgumentList;
\r
176 transformArgumentList = value;
\r
180 protected override void AddParsedSubObject(object obj)
\r
182 if(obj is LiteralControl)
\r
184 DocumentContent = ((LiteralControl)obj).Text;
\r
187 throw new HttpException (HttpRuntime.FormatResourceString (
\r
188 "Cannot_Have_Children_of_Type",
\r
193 [MonoTODO("security")]
\r
194 private void LoadXpathDoc ()
\r
196 if(documentContent != null && documentContent.Length > 0) {
\r
197 xpathDoc = new XPathDocument (new StringReader (documentContent));
\r
201 if (documentSource != null && documentSource.Length != 0) {
\r
202 xpathDoc = new XPathDocument (MapPathSecure (documentSource));
\r
207 [MonoTODO("security")]
\r
208 private void LoadTransform ()
\r
210 if (transform != null)
\r
213 if (transformSource != null && transformSource.Length != 0) {
\r
214 transform = new XslTransform ();
\r
215 transform.Load (MapPathSecure (transformSource));
\r
219 protected override void Render(HtmlTextWriter output)
\r
221 if(document == null)
\r
227 if(document == null && xpathDoc == null)
\r
231 if(transform == null)
\r
233 transform = defaultTransform;
\r
235 if(document != null)
\r
237 Transform.Transform(document, transformArgumentList, output);
\r
240 Transform.Transform(xpathDoc, transformArgumentList, output);
\r