Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - VB script i am using to generate an XML File - Creating or adding to existing one [Thread Next] Re: VB script i am using to generate an XML File - Creating or adding to existing oneTo: NULL Date: 2/3/2006 9:51:00 AM This any good? :-
Const mcsBasePath = "g:\temp\"
Dim mfso: Set mfso = CreateObject("Scripting.FileSystemObject")
Dim moDOM: Set moDOM = Nothing
Dim msPath: msPath = ""
Class CPayment
Public ReceiptType
Public ReceiptMethod
Public ReceiptRef
Public ReceivedFrom
Public AccountNumber
Public Amount
Public BankAccountID
Public DeclineReinstatement
End Class
' Input Loop code here
' Creates a CPayment object with Set oPayment = New CPayment
' populates it with data
' Calls AddPayment with the Batch number and the instance of oPayment as
parameters
If Not moDOM is Nothing Then moDOM.save msPath
Function AddPayment(Batch, Payment)
Dim rootEl, paymentEl
Set rootEl = GetRootForBatch(Batch)
Set paymentEl = AddElem(rootEl, "Payment")
AddElem paymentEl, "ReceiptType", Payment.ReceiptType
AddElem paymentEl, "ReceiptMethod", Payment.ReceiptMethod
AddElem paymentEl, "ReceiptRef", Payment.ReceiptRef
AddElem paymentEl, "ReceivedFrom", Payment.ReceivedFrom
AddElem paymentEl, "AccountNumber", Payment.AccountNumber
AddElem paymentEl, "Amount", Payment.Amount
AddElem paymentEl, "BankAccountID", Payment.BankAccountID
AddElem paymentEl, "DeclineReinstatement", Payment.DeclineReinstatement
End Function
Function GetRootForBatch(Batch)
Dim sPath, p
sPath = mcsBasePath & Batch & ".xml"
If sPath <> msPath Then
If Not moDOM is Nothing Then
moDOM.save msPath
End If
Set moDOM = CreateObject("MSXML2.DOMDocument.3.0")
If gfso.FileExists(sPath) Then
moDOM.load(sPath)
Else
moDOM.loadXML("<ImportPayments />")
Set p = moDOM.createProcessingInstruction("xml", "version='1.0'")
moDOM.insertBefore p, moDOM.documentElement
End If
msPath = sPath
End If
Set GetRootForBatch = moDOM.documentElement
End Function
Function AddElem(parent, name, value)
Set AddElem = parent.ownerDocument.createElement(name)
If Not IsNull(value) AddElem.text = value
End Function
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
