Advantages of XSLT or Linq to XML

c#, html-parsing, linq-to-xml, xslt

Solution

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

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.

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.

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

Problem

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 Advantages: - Easy to change quickly and deploy - Fairly well known XSLT Disadvantages: - Not compiled, so is slower to process - String manipulation can be cumbersome - Will more challenging to get into the C# object at the end Linq to XML Advantages: - Compiled, so it runs faster - Allows for better string manipulation Linq to XML Disadvantages: - Must be compiled for update Edit: 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.

Original source