如何将XML保存到文件 [英] How to save XML to a file

查看:160
本文介绍了如何将XML保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将转换后的XML保存到磁盘上的实际文件中?我是XML/XSLT的新手,我正试图弄清楚这一点.我似乎找不到适合我的示例.例如,我只想将文件保存到c:\ temp \ text.xls.我该如何保存?我是否必须使用Java或.net或其他某种编程语言/api?我希望XSL仅保存文件.

How do you save translated XML to an actual file on disk? I am new to XML/XSLT and I am trying to figure that out. I can't seem to find any examples that work for me. For example, I just want to save the file to c:\temp\text.xls. How to I save it? Do I have to use java or .net or some other programming language/api? I was hoping to have the XSL just save the file.

推荐答案

XSL本身不能做任何事情.这只是将XML文件转换为其他文件的定义.要执行任何操作,您需要在程序中或使用XML Spy之类的工具运行XSL Transform.

The XSL can't do anything by itself. It's just a definition for transforming an XML file into something else. To do anything with it you need to run the XSL Transform in a program, or using a tool like XML Spy.

更新

这是几年前我在VBScript中编写的一个简单示例:

Here's a simple example I wrote some years ago in VBScript:

Dim xml, xsl, htm, fso, flOut

Set xml = CreateObject("MSXML2.DOMDocument")
Set xsl = CreateObject("Msxml2.DOMDocument")
Set fso = CreateObject("Scripting.FileSystemObject")

xml.load WScript.Arguments(0)
xsl.load WScript.Arguments(1)
htm = xml.transformNode(xsl)

Set flOut = fso.CreateTextFile(WScript.Arguments(2))
flOut.Write htm
flOut.close

我称它为xmlTrfm.vbs.像这样使用它:

I called it xmlTrfm.vbs. Use it like this:

xmlTrfm.vbs [sourceFileName].xml [transformFileName].xsl [outputFileName].[ext]

输出文件名的文件扩展名显然取决于XSL转换产生的格式,通常是xml,html或txt,但几乎可以是任何东西.

The file extension for the output file name obviously depends on the format that the XSL transform produces, usually xml, html or txt, but can be almost anything.

这篇关于如何将XML保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆