response.contentType="text/xml"
response.charset="gb2312"
response.write xmldoc.xml
---------------------------------------------------------------
1
2Sub AddElementToParent (domBook, elemParent, sChild, sValue)
3Dim elemSubelement
4Dim textSubelement
5
6Set elemSubelement = domBook.CreateElement(sChild)
7Set textSubelement = domBook.CreateTextNode(sValue)
8elemSubelement.appendChild(textSubelement)
9elemParent.appendChild(elemSubelement)
10
11Set elemSubelement = Nothing
12Set textSubelement = Nothing
13End Sub
14
15Sub WriteNodeXML (nodeTarget)
16Dim i
17
18If nodeTarget.NodeType = 1 Then
19' Element
20Response.Write "<" & nodeTarget.tagName & ">"
21For i = 0 to nodeTarget.childNodes.Length - 1
22WriteNodeXML nodeTarget.childNodes.item(i)
23Next
24Response.Write "
25<!--" & nodeTarget.tagName & "-->
26"
27ElseIf nodeTarget.NodeType = 3 Then
28' Text Node
29Response.Write nodeTarget.data
30End If
31
32End Sub
1<xml id="docBook">
Dim fileInvoice
Dim tsInvoice
Dim domInvoice
Dim elemInvoice
Dim elemLineItem
Dim sFilename
Dim sPath
Dim sLine
Dim sWork
Const ForReading = 1
sFilename = "e:\inetpub\wwwroot\3110\dom\book.txt"
' create the instance of the DOM and the root Book element
Set domBook = CreateObject("Microsoft.XMLDOM")
domBook.async = false
Set elemBook = domBook.CreateElement("Book")
domBook.appendChild elemBook
' open the file
Set fileBook = CreateObject("Scripting.FileSystemObject")
Set tsBook = fileBook.OpenTextFile(sFilename, ForReading)
' process the title and publisher line
sLine = tsBook.ReadLine
sWork = Trim(Mid(sLine, 1, 30)) ' Title
AddElementToParent domBook, elemBook, "Title", sWork
sWork = Trim(Mid(sLine, 31, 20)) ' Publisher
AddElementToParent domBook, elemBook, "Publisher", sWork
sWork = Trim(Mid(sLine, 51, 20)) ' PubDate
AddElementToParent domBook, elemBook, "PubDate", sWork
' process the number of pages, ISBN, and price line
sLine = tsBook.ReadLine
sWork = Trim(Mid(sLine, 1, 10)) ' Number of pages
AddElementToParent domBook, elemBook, "Pages", sWork
sWork = Trim(Mid(sLine, 11, 13)) ' ISBN
AddElementToParent domBook, elemBook, "ISBN", sWork
sWork = Trim(Mid(sLine, 24, 10)) ' Price
AddElementToParent domBook, elemBook, "Price", sWork
' process the abstract line
sLine = tsBook.ReadLine
AddElementToParent domBook, elemBook, "Abstract", sLine
Set elemRecSubjCategories = domBook.CreateElement("RecSubjCategories")
Set elemAuthors = domBook.CreateElement("Authors")
elemBook.appendChild(elemRecSubjCategories)
elemBook.appendChild(elemAuthors)
While Not tsBook.AtEndOfStream
sLine = tsBook.ReadLine
If Left(sLine, 1) = "A" Then
AddElementToParent domBook, elemAuthors, "Author", Mid(sLine, 2)
Else
AddElementToParent domBook, elemRecSubjCategories, "Category", _
Mid(sLine, 2)
End If
Wend
tsBook.Close
WriteNodeXML elemBook
' and clear our objects
Set fileBook = Nothing
Set tsBook = Nothing
Set domBook = Nothing
Set elemBook = Nothing
Set elemAuthor = Nothing
Set elemRecSubjCategories = Nothing
Set elemAuthors = Nothing
1</xml>