2014-12-24 62 views
2

首先,我是一位大型机程序员。我试图编写一个Windows VB脚本来从多个文件中提取信息以用于诊断/调查目的,但是我陷入了困境。 XML是用于直接付款纠纷和外观(浏览器操作)像XML和VBS - 访问孙子节点

<?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://www.w3.org/2001/XMLSchema-instance"> 
<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> 

英国BACS报告我想输出是包含特定值 的SeqNo,PayingBankReference,SUReference,ReasonCode,PayerSortCode,PayerAccount一个CSV文件,付款人姓名

附加到此行我希望每个DateOfDirectDebit和金额值。

现在,我可以得到第一个东西没有问题。我似乎无法得到的是DDCollections/DDCollection子项的循环。任何人都可以给我一些指点吗?

仅供参考,我使用的每个文件的代码是(我尝试了几种变体):

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 

回答

0

如果只有一个这样的DDCollection孩子,那么你可以只刮子与Advice元素仍旧是当前的,即:

DateOfDirectDebit = advice.selectSingleNode("DDCollections/DDCollection/DateOfDirectDebit").Text 
Amount = advice.selectSingleNode("DDCollections/DDCollection/Amount").Text 

然而,如果有多个孩子DDCollection元素,你需要迭代 - 你可以再次使用selectNodes此:

For each ddCollection In advice.selectNodes("DDCollections/DDCollection") 
    DateOfDirectDebit = advice.selectSingleNode("DateOfDirectDebit").Text 
    Amount = advice.selectSingleNode("Amount").Text 
    ** Concatenate here ... 
Next 
+1

干杯,StuartLC。我大部分时间都在那里,但是我今天看到你的回复之前无法完成工作。我在循环中使用了“ddCollection.selectSingleNode”,并且工作正常。我现在有一个快乐的客户,我正在节省大量的时间手动进行提取。 –