Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Scott Morgan" <smorgan@------.--->
To: NULL
Date: 2/2/2006 10:37:00 AM
NEED HELP BAD !!!!  Thanks in advance for all your help.

I have a small VB script i am using to generate an XML File (see below).
What I need help with is the following:
1) I need this script to be able to generate a new unique file if the file
does not exist or
2) Need it to append a node to the file if it does exist
Will need to loop through results until all records are processed.

So it would be a condition of
Batchno = 1234
If batchno = 1234 then add to the XML File else create new XML file named
after the batch name.

My problem is the results will be a mixture so the batch number will change
or could be the same depending on the record.  So the end result could be
multiple XML Files with several nodes per file.  My concern was making sure
the header and closing tags are correct per file.  The batchno is what
really determines when a file is added to or created and added to

Files could be:
1234001.xml (looks like)
<?xml version="1.0" ?>
- <ImportPayments>
- <Payment>
  <ReceiptType>1</ReceiptType>
  <ReceiptMethod>2</ReceiptMethod>
  <ReceiptRef>1834</ReceiptRef>
  <ReceivedFrom>1</ReceivedFrom>
  <AccountNumber>6116242</AccountNumber>
  <Amount>191.8</Amount>
  <BankAccountID>12</BankAccountID>
  <DeclineReinstatement>0</DeclineReinstatement>
  </Payment>
<Payment>
  <ReceiptType>13</ReceiptType>
  <ReceiptMethod>42</ReceiptMethod>
  <ReceiptRef>1434</ReceiptRef>
  <ReceivedFrom>1</ReceivedFrom>
  <AccountNumber>6142</AccountNumber>
  <Amount>120.08</Amount>
  <BankAccountID>12</BankAccountID>
  <DeclineReinstatement>0</DeclineReinstatement>
  </Payment>
<Payment>
  <ReceiptType>1</ReceiptType>
  <ReceiptMethod>2</ReceiptMethod>
  <ReceiptRef>18</ReceiptRef>
  <ReceivedFrom>4</ReceivedFrom>
  <AccountNumber>6116</AccountNumber>
  <Amount>591.8</Amount>
  <BankAccountID>12</BankAccountID>
  <DeclineReinstatement>0</DeclineReinstatement>
  </Payment>
</ImportPayments>

File 2 could be:
9187001.xml (looks like)
<?xml version="1.0" ?>
- <ImportPayments>
- <Payment>
  <ReceiptType>7</ReceiptType>
  <ReceiptMethod>26/ReceiptMethod>
  <ReceiptRef>1532</ReceiptRef>
  <ReceivedFrom>15</ReceivedFrom>
  <AccountNumber>116242</AccountNumber>
  <Amount>199876.50</Amount>
  <BankAccountID>12</BankAccountID>
  <DeclineReinstatement>0</DeclineReinstatement>
  </Payment>
<Payment>
  <ReceiptType>3</ReceiptType>
  <ReceiptMethod>2</ReceiptMethod>
  <ReceiptRef>898123</ReceiptRef>
  <ReceivedFrom>13</ReceivedFrom>
  <AccountNumber>542</AccountNumber>
  <Amount>880.08</Amount>
  <BankAccountID>12</BankAccountID>
  <DeclineReinstatement>0</DeclineReinstatement>
  </Payment>
</ImportPayments>

Here is a copy of the VB script i have now that basically creates the XML
file for only one transaction.

Dim xmlDoc, rootEl, p
Dim fieldReceiptType, fieldReceiptMethod, fieldReceiptRef, fieldReceivedFrom
Dim fieldAccountNumber, fieldAmount, fieldBankAccountID,
fieldDeclineReinstatement

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace = True   'Create a root element and append it to
the document

Set rootEl = xmlDoc.createElement("ImportPayments")
xmlDoc.appendChild rootEl

Set fieldName = xmlDoc.createElement("Payment")
Set fieldReceiptType = xmlDoc.createElement("ReceiptType")
Set fieldReceiptMethod = xmlDoc.createElement("ReceiptMethod")
Set fieldReceiptRef = xmlDoc.createElement("ReceiptRef")
Set fieldReceivedFrom = xmlDoc.createElement("ReceivedFrom")
Set fieldAccountNumber = xmlDoc.createElement("AccountNumber")
Set fieldAmount = xmlDoc.createElement("Amount")
Set fieldBankAccountID = xmlDoc.createElement("BankAccountID")
Set fieldDeclineReinstatement = xmlDoc.createElement("DeclineReinstatement")

fieldReceiptType.Text = "1"
fieldReceiptMethod.Text = "2"
fieldReceiptRef.Text = "1834"
fieldReceivedFrom.Text = "1"
fieldAccountNumber.Text = "6116242"
fieldAmount.Text = "191.8"
fieldBankAccountID.Text = "12"
fieldDeclineReinstatement.Text = "0"

rootEl.appendChild fieldName
fieldName.appendChild fieldReceiptType
fieldName.appendChild fieldReceiptMethod
fieldName.appendChild fieldReceiptRef
fieldName.appendChild fieldReceivedFrom
fieldName.appendChild fieldAccountNumber
fieldName.appendChild fieldAmount
fieldName.appendChild fieldBankAccountID
fieldName.appendChild fieldDeclineReinstatement

'Add an XML processing instruction
'and insert it before the root element
Set p=xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore p,xmlDoc.childNodes(0)

'Save the XML file to the c directory
xmlDoc.Save "c:\trash\test.xml"

'Release all object references
Set xmlDoc = nothing
Set rootEl = nothing
Set fieldReceiptType = nothing
Set fieldReceiptMethod = nothing
Set fieldReceiptRef = nothing
Set fieldReceivedFrom = nothing
Set fieldAccountNumber = nothing
Set fieldAmount = nothing
Set fieldBankAccountID = nothing
Set fieldDeclineReinstatement = nothing
Set fieldName=nothing
Set p = nothing





transparent
Print
Mail
Digg
delicious
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