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

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

问题描述

如何将翻译后的 XML 保存到磁盘上的实际文件中?我是 XML/XSLT 的新手,我正在努力解决这个问题.我似乎找不到任何适合我的例子.例如,我只想将文件保存到 c: emp ext.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: emp ext.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 文件转换为其他文件的定义.要对它进行任何操作,您需要在程序中运行 XSL 转换,或者使用 XML Spy 之类的工具.

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天全站免登陆