从xml节点获取属性

时间:2014-05-08 20:38:50

标签: asp.net xml vb.net

我为flash播放器配置创建了一个xml。我正在尝试将每个节点的属性加载到文本框或下拉列表中。

<config>
  <param name="width" value="960" />
  <param name="height" value="545" />
  <param name="loop" value="0" />
  <param name="autoload" value="1" />
  <param name="autoplay" value="1" />
  <param name="showstop" value="1" />
</config>

Dim XmlDoc As XmlDocument = New XmlDocument

    XmlDoc.Load(Server.MapPath("config.xml"))

    For Each Attribute As XmlAttribute In XmlDoc.DocumentElement.Attributes
        If Attribute.Name = "width" Then
            If Attribute.Name = "value' then" Then
                tbxWidth.Text = Attribute.Value
            End If

        End If


    Next

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

保持你开始的方式......

Dim XmlDoc As XmlDocument = New XmlDocument
XmlDoc.Load(Server.MapPath("config.xml"))

For Each node As XmlNode In XmlDoc.DocumentElement.SelectNodes("param[@name='width']")
    XmlAttribute Attribute = node.Attributes["value"]        
    If Attribute IsNot Nothing Then
            tbxWidth.Text = Attribute.value
    End If
  Next
Next

不是一个VB男孩,所以期待奇怪的傻......

请注意,如果您有多个具有width属性的param节点,则这将采用最后一个...

相关问题