XML and VBS - accessing grandchildren nodes



First off, I'm a mainframe programmer. I'm trying to write a windows VB script to pull information from multiple files for diagnostic/investigation purposes, but I'm getting stuck. The XML is for a UK BACS report of Direct Debit disputes and looks (browser manipulated) like



<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Generated by Oracle Reports version 10.1.2.3.0 -->
<VocaDocument xsi:noNamespaceSchemaLocation="VOCALINK_DDICAdvice.xsd" xmlns:xsi="http://ift.tt/ra1lAU">
<Data>
<Document type="DIRECT DEBIT INDEMNITY CLAIM ADVICE REPORT" created="2014-10-31T01:28:02" schemaVersion="1.0">
<CompanyName>Bacs Payment Schemes Limited</CompanyName>
<ReportTitle>DIRECT DEBIT INDEMNITY CLAIM ADVICE REPORT FOR 30/10/2014</ReportTitle>
<ReportProductionDate>2014-10-31T01:28:02</ReportProductionDate>
<ServiceUserNumber>987654</ServiceUserNumber>
<ServiceUserName>THE COMPANY LIMITED</ServiceUserName>
<NumberOfAdvices>1</NumberOfAdvices>
<NewAdvices>
<DDICAdvice>
<SeqNo>2014102903A987654321</SeqNo>
<PayingBankReference>DDICRBOSABC123</PayingBankReference>
<SUNumber>999888</SUNumber>
<SUReference>ABC12300000</SUReference>
<ReasonCode>2</ReasonCode>
<PayerSortCode>123456</PayerSortCode>
<PayerAccount>987654</PayerAccount>
<PayerName>CUSTOMER</PayerName>
<NoOfAdvForClaim>1</NoOfAdvForClaim>
<TotalAmount>122.65</TotalAmount>
<DDCollections>
<DDCollection>
<DateOfDirectDebit>2014-10-16</DateOfDirectDebit>
<Amount>122.65</Amount>
</DDCollection>
</DDCollections>
</DDICAdvice>
<TotalNumberOfNewAdvices>1</TotalNumberOfNewAdvices>
<TotalValueOfDebits>122.65</TotalValueOfDebits>
<DateOfDebit>2014-11-19</DateOfDebit>
</NewAdvices>
<ReasonCodeMeaning>1 = Amount and / or date of Direct Debit differ from Advance Notice.2 = No Advance Notice received by Payer/or the amount quoted is disputed.3 = DDI cancelled by paying bank.4 = Payer has cancelled DDI direct with service user.5 = AUDDIS service users only - No Instruction held. Payer disputes having given authority.6 = AUDDIS service users only - Signature on DDI is fraudulent or not in accordance with account authorised signature(s).7 = Claim raised at service users request after Direct Debit applied to payers account.8 = Service user name disputed. Payer does not recognise service user collecting Direct Debit.</ReasonCodeMeaning>
</Document>
</Data>
</VocaDocument>


What I want to output is a CSV file containing specific values SeqNo,PayingBankReference,SUReference,ReasonCode,PayerSortCode,PayerAccount,PayerName


Appended to this line I want each of the DateOfDirectDebit and Amount values.


Now, I can get the first stuff no problem. What I can't seem to get is the loop of the DDCollections/DDCollection child. Can anyone give me some pointers?


For reference, the code I'm using for each file is (and I've tried several variants):



For Each advice In xmlDoc.documentElement.selectNodes("/VocaDocument/Data/Document/NewAdvices/DDICAdvice")
SeqNo = advice.selectSingleNode("SeqNo").Text
PayingBankReference = advice.selectSingleNode("PayingBankReference").Text
SUReference = advice.selectSingleNode("SUReference").Text
ReasonCode = advice.selectSingleNode("ReasonCode").Text
PayerSortCode= advice.selectSingleNode("PayerSortCode").Text
PayerAccount= advice.selectSingleNode("PayerAccount").Text
PayerName= advice.selectSingleNode("PayerName").Text
TotalAmount = advice.selectSingleNode("TotalAmount").Text
outLine = SeqNo & "," & PayingBankReference & "," & SUReference & "," & ReasonCode & "," & PayerSortCode & "," & PayerAccount & "," & PayerName & ",""" & TotalAmount & """"
For each ddCollection In advice.ChildNodes
if ddCollection.nodeName = "DateOfDirectDebit" then outline = outLine & "," & ddCollection.Text
if ddCollection.nodeName = "Amount" then outline = outLine & ",""" & ddCollection.Text & """"
Next
objTextFile.WriteLine(OutLine)
Next

No comments:

Post a Comment