|
sdlkfj9
我只知道如何将txt转化为xml,脚本如下。
那位兄台能告诉我如何将xml文件转化为txt。。。。。。。。。。
book.txt
1 |7-100-01532-8/K.206 |ASP.NET XML高级编程 |Chris Knowles,Stephen Mohr等/刘爽 |清华大学出版社 |46 |1.bmp
2 |7-302-04934-3 |ASP与XML 高级编程 |Mark Baartse&Richard Blair等/康博 |清华大学出版社 |78 |2.bmp
3 |7-302-05649-8 |基于XML 的 ASP.NET开发 |Dan Wahlin/王宝良 |清华大学出版社 |42 |3.bmp
4 |7-111-10440-4 |ASP.NET 技术内幕 |Stephen Walther |机械工业出版社 |99 |4.bmp
5 |7-302-06148-3 |XML应用的UML建模技术 |David Carlson/周靖 侯奕萌 沈金河等 |清华大学出版社 |32 |5.bmp
6 |7-111-11385-3 |Effective Java中文版 |Joshua Bloch/潘爱民 |机械工业出版社 |39 |6.bmp
book.vbs
Option Explicit
if WScript.Arguments.length=0 then
WScript.echo "请指向数据源文件!"
WScript.quit
end if
Dim dbfile,db,sdb,i
Dim fso
Dim fo,nf
dbfile = WScript.Arguments(0)
WScript.echo("正在解析"+dbfile+"....")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(dbfile) Then
Set fo = fso.OpenTextFile(dbfile,1)
db = split(fo.ReadAll,Chr(13)&Chr(10))
For each sdb in db
If UBound(split(sdb," |"))<>6 Then
WScript.echo vbCrlf & "未知的数据源文件:" & sdb
WScript.echo "正确的格式:总排序号 |ISBN |书名 |作者/翻译 |出版社 |价格 |图片" & vbCrlf
Else
autoXML split(sdb," |")
End If
Next
Else
WScript.echo "请指向数据源文件!"
WScript.quit
End If
function autoXML(ary)
On Error Resume Next
Dim xmlFile
Dim xmldoc,root,books
xmlFile = "book.xml"
Set xmldoc = WScript.CreateObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.load xmlFile
if xmldoc.parseError.errorCode Then
Dim xmlhead,xslhead
Set xmlhead = xmldoc.createProcessingInstruction("xml","version=""1.0"" encoding=""UTF-8""")
xmldoc.insertBefore xmlhead,xmldoc.childNodes(0)
Set xslhead = xmldoc.createProcessingInstruction("xml-stylesheet","type=""text/xsl"" href=""book.xsl""")
xmldoc.insertBefore xslhead,xmldoc.childNodes(1)
Set books = xmldoc.createElement("books")
xmldoc.appendChild books
Else
Set books = xmldoc.documentElement
End If
Dim book,nodes,node
Set book = xmldoc.createElement("book")
books.appendChild book
nodes = split("id,ISBN,book_name,writer,publish,price,img",",")
for i=0 to UBound(nodes)
Set node = xmldoc.createElement(nodes(i))
node.text = ary(i)
book.appendChild node
Next
xmldoc.save xmlFile
If Err.number<>0 Then
WScript.echo "保存失败!原因:" & Err.Description
Else
WScript.echo "《" & ary(2) & "》保存成功!"
End If
End Function
[ 本帖最后由 sinpa 于 2006-8-24 23:14 编辑 ] |
|