Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: VB script i am using to generate an XML File - Creating or adding to existing one

From: "Anthony Jones" <Ant@------------.--->
To: 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





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent