Reputation: 301
Say I have an XSLT file like below:
`<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-
prefixes="xs math"
version="3.0">`
....... and so on.
I need the output as 3.0 because the above file has version="3.0". I want to use C# to get this given the XSLT is in string format
Upvotes: 2
Views: 741
Reputation: 167401
Use XElement.Parse(yourString).Attribute("version").Value
, where you add using System.Xml.Linq;
. See https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-overview for details of the used API.
Upvotes: 1
Reputation: 34421
Using xml linq :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
string version = (string)doc.Root.Attribute("version");
}
}
}
Upvotes: 2