Tips - Visual Basic

【TOP】

XML文書をXSLT変換する
XMLファイル(abcde.xml)をXSLT(henkan.xsl)ファイルによりHTML(Output.html)に変換してみます。
XML:eXtensible Markup Language
XSLT:XSL Transform
XSL Transform については「簡単な XSLT を使って XML を変換してみよう!」も見てみてください。
Imports System.IO Imports System.Xml Imports System.Xml.XPath Imports System.Xml.Xsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'XSLT文書 'Dim xslt As New XslTransform // v1.1 旧式 Dim xslt As New XslCompiledTransform ''v2.0 'XML文書 'Dim xpathDoc As New XPathDocument("abcde.xml") // v1.1 旧式 Dim xpathDoc As New XmlTextReader("abcde.xml") ''v2.0 '出力用FileStream Dim outStream As New FileStream("Output.html", FileMode.Create) 'XmlTextWriter用StreamWriter Dim twriter As New StreamWriter(outStream, System.Text.Encoding.GetEncoding("utf-8")) 'XmlTextWriter Dim xwriter As New XmlTextWriter(twriter) 'インデントを設定する。 xwriter.Indentation = 4 'インデントを有効にする。 xwriter.Formatting = Formatting.Indented 'XSLT文書読み込む。 xslt.Load("henkan.xsl") 'XSLT変換を実行する。 xslt.Transform(xpathDoc, Nothing, xwriter, Nothing) 'オブジェクトを開放する。 xslt = Nothing xpathDoc = Nothing twriter.Close() xwriter.Close() outStream.Close()
【戻る】