帮助阅读XML数据 [英] Help Reading XML data

查看:96
本文介绍了帮助阅读XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习使用xml,我现在能够很好地创建我的布局但是我在从类别字段中获取属性数据时遇到问题。下面是我的xml,我需要帮助找到循环每个类别的最简单方法,并获取名称并将其设置为真或假。任何帮助都会很棒。



 <   HelpBox  >  
< 分类 >
< 类别 已选择 = True 名称 = 管理工具 > < / Category >
< 类别 已选择 = False 名称 = 脚本 > < / Category >
< 类别 已选择 = False 名称 = 剪贴板 > < / Category >
< / Categorys >
< 操作 >
< 项目 名称 = < span class =code-keyword> RDC 图标 = 1 TaskType = 启动 类别 = Adm在工具 >
< 文件 > C:\ Windows \ System32 \mstsc.exe < /文件 >
< ; Arg / < span class =code-keyword>>
< / Item >
< 项目 名称 = MSRA 图标 = 2 < span class =code-attribute> TaskType = 启动 类别 = 管理工具 >
< 文件 > C:\ Windows \ System32 \ msra.exe < /文件 >
< Arg > offerra < / Arg >
< / Item >
< / Actions >
< / HelpBox >

解决方案

我想通了。



 使用 reader 作为 XmlReader = XmlReader.Create(  C:\ Users \ shuppz \Desktop \XmlTest.xml
while reader.Read()
' 检查启动元素。
如果 reader.IsStartElement()然后

如果 reader.Name = 类别 然后
' 获取名称属性。
Dim xName As 字符串 = reader( 名称
如果 xName IsNot 没有 然后
MsgBox( String .Format( 具有属性名称:{0},xName))
结束 如果

结束 如果
结束 如果
结束 < span class =code-keyword> while
结束 使用


I have been learning to work with xml and I'm now able to create my layout just fine but Im having issues getting attribute data from the category fields. Below is a look at my xml, I need help finding the easiest way to loop through each category and get the name and weather its set to true or false. Any help would be great.

<HelpBox>
  <Categorys>
    <Category Selected="True" Name="Admin Tools"></Category>
    <Category Selected="False" Name="Scripts"></Category>
    <Category Selected="False" Name="Clipboard"></Category>
  </Categorys>
  <Actions>
    <Item Name="RDC" Icon="1" TaskType="Launch" Category="Admin Tools">
      <File>C:\Windows\System32\mstsc.exe</File>
      <Arg />
    </Item>
    <Item Name="MSRA" Icon="2" TaskType="Launch" Category="Admin Tools">
      <File>C:\Windows\System32\msra.exe</File>
      <Arg>offerra</Arg>
    </Item>
  </Actions>
</HelpBox>

解决方案

I figured it out.

Using reader As XmlReader = XmlReader.Create("C:\Users\shuppz\Desktop\XmlTest.xml")
    While reader.Read()
        ' Check for start elements.
        If reader.IsStartElement() Then

            If reader.Name = "Category" Then
                ' Get name attribute.
                Dim xName As String = reader("Name")
                If xName IsNot Nothing Then
                    MsgBox(String.Format("  Has attribute name: {0}", xName))
                End If

            End If
        End If
    End While
End Using


这篇关于帮助阅读XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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