[英]How to get the version number from a given XSLT file .
说我有一个XSLT文件,如下所示:
`<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.
我需要输出为3.0,因为上面的文件具有version =“ 3.0”。 鉴于XSLT为字符串格式,我想使用C#来获取此信息
使用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");
}
}
}
使用XElement.Parse(yourString).Attribute("version").Value
,在其中using System.Xml.Linq;
。 有关使用的API的详细信息,请参见https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-overview 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.