Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

Firstly, I wish to thank the dedicated professionals on this site who assist us, the newbies. I'm now an intermediate programmer and some of the professionals on this site has assisted me by answering few of the questions that I have posted.

Now I have an issue where I wish to get the tags together with the elements from an xml file onto a text file. The following is the xml file details and its intended output.

XML
<?xml version="1.0"?>
<Cheque_Deposit_Transactoin>
    <Transaction_Date>17/04/14</Transaction_Date>
  <Transaction_Time>11:07</Transaction_Time>
  <Transaction_Sequence_Number>0124</Transaction_Sequence_Number>
  <Total_Cheque_Deposit_Amount>2000.00</Total_Cheque_Deposit_Amount>
  <Card_Number>601302....5796</Card_Number>
  <Account_Number>001013039738</Account_Number>
  <Cheques><Cheque index="1">
    <MICR>*1056145* 030-500T 0002003456*</MICR>
    <Cheque_Serial_Number>105614</Cheque_Serial_Number>
    <Cheque_Scanned_Amount>200000</Cheque_Scanned_Amount>
    <Cheque_Disposition>1</Cheque_Disposition>
  </Cheque></Cheques>
</Cheque_Deposit_Transactoin>



Output that I wish to get from the above is as follows:

Cheque_Deposit_Transactoin
Transaction_Date:17/04/14
Transaction_Time:11:07
Transaction_Sequence_Number:0124
Total_Cheque_Deposit_Amount:2000.00
Card_Number:601302....5796
Account_Number:001013039738
Cheques
MICR:*1056145* 030-500T 0002003456
Cheque_Serial_Number:105614
Cheque_Scanned_Amount:200000


Please assist. I have actually managed to get the elements using the following code but I also would like to get the tags together and get the result onto a text file.

VB
Dim xmldoc As New XmlDataDocument()
        Dim xmlnode As XmlNodeList
        Dim i As Integer
        Dim x As Integer
        Dim str As String

        Dim fs As New FileStream("Test.xml", FileMode.Open, FileAccess.Read)
        xmldoc.Load(fs)
        xmlnode = xmldoc.GetElementsByTagName("Cheque_Deposit_Transactoin")
        For i = 0 To xmlnode.Count - 1
            For x = 0 To xmlnode(i).ChildNodes.Count - 1
                xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
                str = xmlnode(i).ChildNodes.Item(x).InnerText.Trim()
                MsgBox(str)
                x = ++x
            Next
        Next
Posted
Updated 8-May-14 14:28pm
v2
Comments
Shao Voon Wong 8-May-14 21:07pm    
Do you know the tags in the XML beforehand?

1 solution

Check this out: xmlreader-vbnet[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900