📄 xml.cs
字号:
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Web.UI;
using System.Web.Caching;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for Xml.
/// </summary>
public class Xml : Control
{
private const string identityXslStr = "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match=\"/\"> <xsl:copy-of select=\".\"/> </xsl:template> </xsl:st" + "ylesheet>";
private System.Xml.XmlDocument _document;
private System.Xml.XPath.XPathDocument _xpathDocument;
private System.Xml.Xsl.XslTransform _transform;
private System.Xml.Xsl.XsltArgumentList _transformArgumentList;
private string _documentContent;
private string _documentSource;
private string _transformSource;
private static System.Xml.Xsl.XslTransform _identityTransform;
static Xml()
{
XmlTextReader local0;
local0 = new XmlTextReader(new StringReader("<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match=\"/\"> <xsl:copy-of select=\".\"/> </xsl:template> </xsl:stylesheet>"));
Xml._identityTransform = new XslTransform();
Xml._identityTransform.Load(local0);
}
public Xml() : base()
{
}
protected virtual void AddParsedSubObject(object obj)
{
if (obj as LiteralControl != null)
{
this.DocumentContent = ((LiteralControl) obj).Text;
return;
}
throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Xml", obj.GetType().Name.ToString()));
}
private void LoadTransformFromSource()
{
string local0;
CacheInternal local1;
string local2;
CacheDependency local3;
if (this._transform != null)
return;
if (this._transformSource == null || this._transformSource.Length == 0)
return;
local0 = this.MapPathSecure(this._transformSource);
local1 = HttpRuntime.CacheInternal;
local2 = "System.Web.UI.WebControls:" + local0;
this._transform = (XslTransform) local1.Get(local2);
if (this._transform == null)
{
local3 = new CacheDependency(local0);
try
{
this._transform = new XslTransform();
this._transform.Load(local0);
local1.Insert(local2, this._transform, local3);
}
finally
{
if (local3 == null)
{
// goto i-1;
}
local3.Dispose();
}
}
}
private void LoadXmlDocument()
{
string local0;
CacheInternal local1;
string local2;
CacheDependency local3;
XmlDocument local4;
if (this._documentContent != null && this._documentContent.Length > 0)
{
this._document = new XmlDocument();
this._document.LoadXml(this._documentContent);
return;
}
if (this._documentSource == null || this._documentSource.Length == 0)
return;
local0 = this.MapPathSecure(this._documentSource);
local1 = HttpRuntime.CacheInternal;
local2 = "System.Web.UI.WebControls.LoadXmlDocument:" + local0;
this._document = (XmlDocument) local1.Get(local2);
if (this._document == null)
{
local3 = new CacheDependency(local0);
try
{
this._document = new XmlDocument();
this._document.Load(local0);
local1.Insert(local2, this._document, local3);
}
finally
{
if (local3 == null)
{
// goto i-1;
}
local3.Dispose();
}
}
lock (this._document)
this._document = (XmlDocument) this._document.CloneNode(true);
}
private void LoadXPathDocument()
{
StringReader local0;
string local1;
CacheInternal local2;
string local3;
CacheDependency local4;
if (this._documentContent != null && this._documentContent.Length > 0)
{
local0 = new StringReader(this._documentContent);
this._xpathDocument = new XPathDocument(local0);
return;
}
if (this._documentSource == null || this._documentSource.Length == 0)
return;
local1 = this.MapPathSecure(this._documentSource);
local2 = HttpRuntime.CacheInternal;
local3 = "System.Web.UI.WebControls.LoadXPathDocument:" + local1;
this._xpathDocument = (XPathDocument) local2.Get(local3);
if (this._xpathDocument == null)
{
local4 = new CacheDependency(local1);
try
{
this._xpathDocument = new XPathDocument(local1);
local2.Insert(local3, this._xpathDocument, local4);
}
finally
{
if (local4 == null)
{
// goto i-1;
}
local4.Dispose();
}
}
}
protected virtual void Render(HtmlTextWriter output)
{
if (this._document == null)
this.LoadXPathDocument();
this.LoadTransformFromSource();
if (this._document == null && this._xpathDocument == null)
return;
if (this._transform == null)
this._transform = Xml._identityTransform;
if (this._document != null)
{
this.Transform.Transform(this._document, this._transformArgumentList, output);
return;
}
this.Transform.Transform(this._xpathDocument, this._transformArgumentList, output);
}
public XmlDocument Document
{
get
{
if (this._document == null)
this.LoadXmlDocument();
return this._document;
}
set
{
this.DocumentSource = null;
this._xpathDocument = null;
this._documentContent = null;
this._document = value;
}
}
public string DocumentContent
{
get
{
return System.String.Empty;
}
set
{
this._document = null;
this._xpathDocument = null;
this._documentContent = value;
}
}
public string DocumentSource
{
get
{
if (this._documentSource != null)
return this._documentSource;
return System.String.Empty;
}
set
{
this._document = null;
this._xpathDocument = null;
this._documentContent = null;
this._documentSource = value;
}
}
public XslTransform Transform
{
get
{
return this._transform;
}
set
{
this.TransformSource = null;
this._transform = value;
}
}
public XsltArgumentList TransformArgumentList
{
get
{
return this._transformArgumentList;
}
set
{
this._transformArgumentList = value;
}
}
public string TransformSource
{
get
{
if (this._transformSource != null)
return this._transformSource;
return System.String.Empty;
}
set
{
this._transform = null;
this._transformSource = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -