Parse XML

  • Hi Everyone. I am facing problem while parsing the below XML.

    <site>

    <status>0</status>

    <bankAccount uniqueId="23232323" acctType="checking">

    <accountName>TESTDATA</accountName>

    <accountNumber>503-1123xxx</accountNumber>

    <accountHolder>accountHolder</accountHolder>

    <balance balType="availableBalance">

    <curAmt curCode="USD">54.78</curAmt>

    </balance>

    <balance balType="currentBalance">

    <curAmt curCode="USD">44.78</curAmt>

    </balance>

    <transactionList>

    <transaction uniqueId="14141414" type="debit" baseType="debit">

    <description>CHECK # 998</description>

    <checkNumber>998</checkNumber>

    <amount curCode="USD">59.00</amount>

    <link>link</link>

    <category>category</category>

    <transDate localFormat="MM/dd/yy">2005-07-16T00:00:00</transDate>

    </transaction>

    <transaction uniqueId="1111111" type="deposit" baseType="credit">

    <description>DESC</description>

    <link>http://www.abc.com</link&gt;

    <amount curCode="USD">343465.00</amount>

    <transDate localFormat="yyyy-MM-dd">2005-07-16T00:00:00</transDate>

    <postDate localFormat="yyyy-MM-dd">2005-07-16T00:00:00</postDate>

    <checkNumber>DAG-333</checkNumber>

    <category categoryId="333">other</category>

    </transaction>

    </transactionList>

    </bankAccount>

    I tried the following code in Script component.

    Public Overrides Sub CreateNewOutputRows()

    'Read A/c Details for each node from XML

    For Each xNode As XmlNode In xDoc.SelectNodes("//bankAccount")

    BankAccBuffer.AddRow()

    BankAccBuffer.AccountName = xNode.ChildNodes(0).InnerText

    BankAccBuffer.AccountNumber = xNode.ChildNodes(1).InnerText

    BankAccBuffer.AccountHolder = xNode.ChildNodes(2).InnerText

    BankAccBuffer.AvailableBalance = xNode.ChildNodes(3).InnerText

    BankAccBuffer.CurrentBalance = xNode.ChildNodes(4).InnerText

    BankAccBuffer.CurrentBalance = xNode.ChildNodes(5).InnerText

    Next

    End Sub

    First 5 nodes are fetched perfectly but when it comes to xNode.ChildNodes(5).InnerText the value "CHECK # 998" is not fetched rather it reads the whole rest of the values - "CHECK # 99899859.00linkcategory2005-07-16T00:00:00DESChttp://www.altova.com343465.002005-07-16T00:00:002005-07-16T00:00:00DAG-333other"

    so I would like to know where i am going wrong or advice me with an alternate to handle this xml file. Thanking you in advance

  • The fifth node(Transaction List) does not just have a single node under it but multiple nodes. (In fact i would have thought that even with 'Balance' nodes, you would have not gotten the values straight by saying .childnodes but it depends on the parser you are using....not sure)

    So there are multiple 'Transaction' nodes under the TransactionList node and multiple nodes under the Transaction node.

    You can check the exact syntax but you will have to do something like......

    NodeList n = xNode.ChildNodes(5).NodeList()

    Then loop through this list....go through each Transaction node and then say something like tx_node.Child[0] //for DESC

    tx_node.Child[1] //for CheckNumber

    Sorry i don't remember the syntax but just to give the correct idea.

    Hope this helps....

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply