1

我得到了类型值“戏剧”,但它只有一个,我怎样才能得到三个类型值,比如“戏剧”、“喜剧”和“惊悚”?

<details>
    <id>734357</id>
    <title>vb best</title>
    <year>2012-07-27</year>
    <genre>Drama</genre>
    <genre>Comedy</genre>
    <genre>Thriller</genre
    <studio></studio>
</details>


    Dim doc As New XmlDocument()
    Dim nodes As XmlNodeList
    doc.Load(FILE_NAME)

    nodes = doc.SelectNodes("/details")
    Dim node As XmlNode

    For Each node In nodes

        Dim nodeid As XmlNode = node.SelectSingleNode("id")
        If nodeid IsNot Nothing Then
            MsgBox(node.SelectSingleNode("id").InnerText)
        End If
        Dim nodeimdb_id As XmlNode = node.SelectSingleNode("title")
        If nodeimdb_id IsNot Nothing Then
            MsgBox(node.SelectSingleNode("title").InnerText)
        End If

        Dim nodegenre As XmlNode = node.SelectSingleNode("genre")
        If nodegenre IsNot Nothing Then
            MsgBox(node.SelectSingleNode("genre").InnerText)
        End If

    Next
4

2 回答 2

0
Dim doc As New XmlDocument()
Dim nodes As XmlNodeList
doc.Load(FILE_NAME)

nodes = doc.SelectNodes("/details")
Dim node As XmlNode

For Each node In nodes

    Dim nodeid As XmlNode = node.SelectSingleNode("id")
    If nodeid IsNot Nothing Then
        MsgBox(nodeid.InnerText)
    End If
    Dim nodeimdb_id As XmlNode = node.SelectSingleNode("title")
    If nodeimdb_id IsNot Nothing Then
        MsgBox(nodeimdb_id.InnerText)
    End If

    Dim genreNodes As XmlNodeList = node.SelectNodes("genre")
    For each genreNode in genreNodes
        MsgBox(genreNode.InnerText)
    Next

Next

将是一种方式。请注意,既然您已经获得了节点,则无需再次获得它。

于 2012-10-23T21:14:31.243 回答
0

使用.SelectNodes代替.SelectSingleNode

于 2012-10-23T21:14:33.787 回答