从XML文件中获取价值 [英] Get value from XML file

查看:91
本文介绍了从XML文件中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我已经开始学习XML并编写一个简单的程序来从XML文件中获取数据并写入文件。

我有很多行如:< dipswitch name =Rack Test(Cheat)>

如何通过所有标签获得atribuite名称< dipswirch>?

我使用标准XML库和我的代码现在是:



Hello!
I have started to learn XML and write a simple program for getting data from XML file and writes to file.
I have a much line such as: "<dipswitch name="Rack Test (Cheat)">"
How i can get atribuite name by all tags <dipswirch>?
I use standart XML library and my code is now:

Try
       Dim m_xmld As XmlDocument
       Dim m_nodelist As XmlNodeList
       Dim m_node As XmlNode

       m_xmld = New XmlDocument()
       m_xmld.Load("D:\test.xml")
       m_nodelist = m_xmld.SelectNodes("dipswitch")

       For Each m_node In m_nodelist

           MessageBox.Show(m_node.InnerText)

       Next
   Catch errorVariable As Exception

   End Try



谢谢!


Thank you!

推荐答案

输入:

< H>

< H1>

< font> jkhhujhjhj< / font>

< size> 12< / size>

< / H1>

< / H>





Input:
<H>
<H1>
<font>jkhhujhjhj</font>
<size>12</size>
</H1>
</H>


Dim XMLDoc As New XmlDocument()
  Dim nodlist As XmlNodeList
  Dim node As System.Xml.XmlNode
XMLDoc.Load ("C:\path.xml")
 nodlist = XMLDoc.SelectNodes("/H/H1")
     For Each node As System.Xml.XmlNode In nodlist

                    TextBox1.Text = node.ChildNodes.Item(0).InnerText
                    TextBox2.Text = node.ChildNodes.Item(1).InnerText
     Next





输出:

Textbox1.Text = jkhhujhjhj

Textbox2.Text = 12



Output:
Textbox1.Text=jkhhujhjhj
Textbox2.Text=12
Hope this Will help you to understand abt how to get the values from the xml.......


这篇关于从XML文件中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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