何时使用xml而不是HTML?(When to use xml with xsl instead of HTML?)

编程入门 行业动态 更新时间:2024-10-16 02:23:26
何时使用xml而不是HTML?(When to use xml with xsl instead of HTML?)

我喜欢.NET webcontrols和你操作的东西,这是普遍的共识,但是XML和XSL是如此之大,因为你有独立于平台和语言的UI逻辑,所以总有一天我将应用程序更改为php,java或者其他我可以重用所有表示逻辑。 而且,XSL有可能在渲染之前调用.NET(或其他)方法。

你什么时候正常使用XML / XSL? 为什么不经常使用它?

I like .NET webcontrols and you manipulate things, that's common consensus, but XML and XSL is so great, because you have UI logic that is platform & language-independent, so one day I change the app to php, java or whatever and i can reuse all the presentation logic. Moreover, XSL has the possibility to call .NET (or whatever) methods before rendering.

When do you use XML/XSL normally? why no to use it more frequently?

最满意答案

而不是HTML?

我经常使用它来代替asp.net控件,因为它提供了对2.0中V和C的关注点的分离,而你没有在.NET 2.0中获得开箱即用。

显然,有一百万个其他用途与asp.net控件无关。


编辑:实现的草图

public class xsltmanager { /* constructor (singleton) which defines a file watcher for *.xsl in the path of your choice */ //just a mutex for thread safety private object Mutex = new object(); //caching XslCompiledTransforms private Dictionary<string, XslCompiledTransform> cTransforms = new Dictionary<string, XslCompiledTransform>(); public XslCompiledTransform fetch(string identifier) { if (!this.cTransforms.ContainsKey(identifier)) { lock (this.Mutex) { if (!this.cTransforms.ContainsKey(identifier)) { XslCompiledTransform xslDoc = new XslCompiledTransform(); xslDoc.Load(/* file path based on identifier */); this.cTransforms.Add(identifier, xslDoc); } } } return this.cTransforms[identifier]; } /* other util xslt methods - namespace wash, doc merge, whatever */ } public class myPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //get source data XPathDocument xPathDoc = myGetXMLMethod(); //transform params XsltArgumentList oArgs = new XsltArgumentList(); /* add params as required */ //fetching and executing the transform directly to the Response here xsltmanager.instance.get(@"foo\bar\baz").Transform(xPathDoc, oArgs, Response.OutputStream); } }

Instead of HTML?

I use it constantly in place of asp.net controls since it affords the separation of concerns for the V and the C in 2.0 that you don't get in .NET 2.0 out of the box.

Obviously there's a million other uses unrelated to asp.net controls.


Edit: a sketch of an implementation

public class xsltmanager { /* constructor (singleton) which defines a file watcher for *.xsl in the path of your choice */ //just a mutex for thread safety private object Mutex = new object(); //caching XslCompiledTransforms private Dictionary<string, XslCompiledTransform> cTransforms = new Dictionary<string, XslCompiledTransform>(); public XslCompiledTransform fetch(string identifier) { if (!this.cTransforms.ContainsKey(identifier)) { lock (this.Mutex) { if (!this.cTransforms.ContainsKey(identifier)) { XslCompiledTransform xslDoc = new XslCompiledTransform(); xslDoc.Load(/* file path based on identifier */); this.cTransforms.Add(identifier, xslDoc); } } } return this.cTransforms[identifier]; } /* other util xslt methods - namespace wash, doc merge, whatever */ } public class myPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //get source data XPathDocument xPathDoc = myGetXMLMethod(); //transform params XsltArgumentList oArgs = new XsltArgumentList(); /* add params as required */ //fetching and executing the transform directly to the Response here xsltmanager.instance.get(@"foo\bar\baz").Transform(xPathDoc, oArgs, Response.OutputStream); } }

更多推荐

本文发布于:2023-08-07 06:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   xml   xsl   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!