2017-11-11 2 views
2

은 내가 XSLT 파일을 아래와 같이이 말 : 위의 파일 버전 = "3.0"을 가지고 있기 때문에주어진 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로 출력을해야합니다. XSLT가 문자열 형식 인 경우 C#을 사용하려고합니다.

답변

1

using System.Xml.Linq;을 추가하여 사용하십시오. 사용 된 API에 대한 자세한 내용은 https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-overview을 참조하십시오.

+0

경우는 어떻게? – swifty

+0

다른 API와 마찬가지로이 API를 사용하려면 해당 문서를 읽기 시작하고 클래스'XElement'에는'Load' 메소드가 있습니다. https://docs.microsoft.com/en-us/dotnet/api/system .xml.linq.xelement.load? view = netframework-4.7.1. 예를 들어'Stream'을 취하는 하나의 과부하가 있습니다. –

2

의 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"); 
     } 
    } 
} 
관련 문제