Results 1 to 3 of 3

Thread: VB.NET: Extract element and attribute using ChildNode method......[Resolved]

Threaded View

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    Question VB.NET: Extract element and attribute using ChildNode method......[Resolved]

    Say I have these Xml tag:
    Code:
      <hi help=”example”>
        <how>
          <to>do</to>
          <or> 
            <give suggestion=”on” doing=”it”/>
          </or>
          <thank>bye</thank>
        </how>
        <how>
            …
        </how>
      </hi>
    I want to use the childNode method to do for example:
    Code:
    Dim xdoc As XmlDocument
    Dim nodelist As XmlNodeList
    Dim node As XmlNode
    Dim to, thank, suggestion, doing As String
    xdoc = New XmlDocument
    
    xdoc.LoadXml("example.xml")
    
    nodelist = xdoc.SelectNodes("/hi/how")
    
       For Each node In nodelist
            to = node.ChildNodes.Item(0).InnerText
            thank = node.ChildNodes.Item(2).InnerText
            listbox.Items.Add( to & thank)
            Dim giveNode As XmlNode = node.ChildNodes.Item(1).ChildNodes.Item(0)
            suggestion = giveNode.Attributes(0).Value
            doing = giveNode.Attributes(1).Value
            listbox.Items.Add( suggestion & doing)
        Next
    I can use the above code to get the content of to, thank, suggestion and doing...but how to get back the same content if i change the Xml tag to:
    Code:
      <hi help=”example”>
        <how to=”do”>
          <give suggestion=”on” doing=”it”/> 
          <thank>bye</thank>
        </how>
        <how>
            …
        </how>
      </hi>
    Thanks
    Last edited by toytoy; Dec 13th, 2004 at 08:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width