XSLT或LINQ到XML的优点 [英] Advantages of XSLT or Linq to XML

查看:150
本文介绍了XSLT或LINQ到XML的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么优势,有在C#中使用XSLT两种或LINQ到XML的HTML解析?这是HTML是否已被清理,因此是有效的XHTML的假设下。这些数值最终将进入一个C#对象进行验证和处理。

What advantages are there for using either XSLT or Linq to XML for HTML parsing in C#? This is under the assumption that the html has been cleaned so it is valid xhtml. These values will eventually go into a c# object to be validated and processed.

请让我知道如果这些都是有效的,如果有其他的事情要考虑。

Please let me know if these are valid and if there are other things to consider.

XSLT优点:


  • 易于迅速改变和部署

  • 相当著名的

XSLT缺点:


  • 未编译,所以比较慢处理

  • 字符串操作会很麻烦

  • 将更有挑战性进入C#对象在结束

的LINQ to XML的优点:

Linq to XML Advantages:


  • 编译,所以它的运行速度更快

  • 可以更好地进行字符串操作

的LINQ to XML缺点:

Linq to XML Disadvantages:


  • 必须被编译为更新

编辑:
我要澄清,我想这些运行长期的网站可以更新它们的布局曾经一段时间。这是的更大的原因,我想我会用的东西,并不需要编译之一。

I should clarify, I want these to run long term an the website may update their layout once a while. That was one of the bigger reason I thought I would use something that didn't require compiling.

推荐答案

如果没有进一步的了解您的使用情况下,很难给你一般建议。

Without further knowing your use case it is hard to give you general recommendations.

总之,你是有些比较苹果和桔子。 LINQ到XML(LINQ和一般)是一种查询语言,而XSLT是一种编程语言来转换XML树结构。这些是不同的概念。每当你想从数据源中提取一定的特定的信息做任何你需要它(无论是在C#对象来设置字段)做的,你会使用的查询语言。的转换,相反,将是您的数据的一个XML表示转换成另一种XML表示很有用的。

Anyhow, you are somewhat comparing apples and oranges. LINQ to XML (and LINQ in general) is a query language whereas XSLT is a programming language to transform XML tree structures. These are different concepts. You would use a query language whenever you want to extract a certain specific piece of information from a data source to do whatever you need to do with it (be it to set fields in a C# object). A transformation, in contrast, would be useful to convert one XML representation of your data into another XML representation.

所以,如果你的目标是创建XML C#对象,可能不希望使用XSLT但是任何由.NET Framework提供了处理XML数据的其他技术:老的XmlDocument 的XmlReader 的XPathDocument 的XmlSerializer 的XDocument 。每个人都有它的特殊的优势和劣势,取决于输入的大小,输入复杂程度,所需的输出等。

So if your aim is to create C# objects from XML, you probably don't want to use XSLT but any of the other technologies offered by the .NET Framework to process XML data: the old XmlDocument, XmlReader, XPathDocument, XmlSerializer or XDocument. Each has it's special advantages and disadvantages, depending on input size, input complexity, desired output etc.

既然你只处理HTML,你可能还需要有一个看 HTML敏捷性包CodePlex上的。

Since you are dealing with HTML only, you might also want to have a look at the HTML Agility Pack on CodePlex.

这篇关于XSLT或LINQ到XML的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆