XML文件 - 使用标签读取元素/内容 [英] XML File - Reading elements/contents with Tags

查看:66
本文介绍了XML文件 - 使用标签读取元素/内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



首先,我要感谢本网站上专门的专业人士,他们协助我们,新手。我现在是一名中级程序员,本网站上的一些专业人士通过回答我发布的一些问题来帮助我。



现在我有一个问题我希望将标签与xml文件中的元素一起放到文本文件中。以下是xml文件的详细信息及其预期输出。



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 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>







我希望从上面得到的输出如下:



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

支票

MICR:* 1056145 * 030-500T 0002003456

Cheque_Serial_Number:105614

Cheque_Scanned_Amount:200000




请协助。我实际上设法使用以下代码获取元素,但我也希望将标记放在一起并将结果放到文本文件中。






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.

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

解决方案

检查一下: xmlreader-vbnet [ ^ ]


这篇关于XML文件 - 使用标签读取元素/内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆