Results 1 to 5 of 5

Thread: Parse xml to listview vbnet

  1. #1
    Junior Member
    Join Date
    May 12
    Posts
    22

    Parse xml to listview vbnet

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
      <Errors />
      <Warnings />
      <RequestedCommand>namecheap.domains.check</RequestedCommand>
      <CommandResponse Type="namecheap.domains.check">
        <DomainCheckResult Domain="domain1.com" Available="false" />
        <DomainCheckResult Domain="domain2.com" Available="false" />
      </CommandResponse>
      <Server>WEB1-SANDBOX1</Server>
      <GMTTimeDifference>--4:00</GMTTimeDifference>
      <ExecutionTime>2.391</ExecutionTime>
    </ApiResponse>

    i thought it would be like this but apparently not


    VB.NET Code:
    1. Dim doc As New XmlDocument
    2.         doc.Load("https://api.sandbox.namecheap.com/xml.response?ApiUser=xxxx&ApiKey=xxxx&UserName=xxxx&ClientIp=xxxx&Command=namecheap.domains.check&DomainList=domain1.com,domain2.com")
    3.  
    4.         Dim nodes As XmlNodeList = doc.SelectNodes("CommandResponse/DomainCheckResult")
    5.  
    6.         For Each node As XmlNode In nodes
    7.             Dim Remarks As String = node.SelectSingleNode("Domain").InnerText
    8.             Dim Time As String = node.SelectSingleNode("Available").InnerText
    9.             ListView1.Items.Add(New ListViewItem(New String() {Remarks, Time}))
    10.         Next

  2. #2
    vb Coda .paul.'s Avatar
    Join Date
    May 07
    Location
    Chelmsford UK
    Posts
    16,495

    Re: Parse xml to listview vbnet

    try this:

    vb.net Code:
    1. Imports <xmlns:ns="http://api.namecheap.com/xml.response">
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim xml = _
    7.         <?xml version="1.0" encoding="utf-8"?>
    8.         <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
    9.             <Errors/>
    10.             <Warnings/>
    11.             <RequestedCommand>namecheap.domains.check</RequestedCommand>
    12.             <CommandResponse Type="namecheap.domains.check">
    13.                 <DomainCheckResult Domain="domain1.com" Available="false"/>
    14.                 <DomainCheckResult Domain="domain2.com" Available="false"/>
    15.             </CommandResponse>
    16.             <Server>WEB1-SANDBOX1</Server>
    17.             <GMTTimeDifference>--4:00</GMTTimeDifference>
    18.             <ExecutionTime>2.391</ExecutionTime>
    19.         </ApiResponse>
    20.  
    21.         Dim nodes = From node In xml...<ns:CommandResponse>.<ns:DomainCheckResult> _
    22.                     Select New With { _
    23.                     .domain = node.@Domain, _
    24.                     .available = node.@Available}
    25.  
    26.         For Each node In nodes
    27.             ListView1.Items.Add(New ListViewItem(New String() {node.domain, node.available}))
    28.         Next
    29.  
    30.     End Sub
    31. End Class

  3. #3
    Junior Member
    Join Date
    May 12
    Posts
    22

    Re: Parse xml to listview vbnet

    Quote Originally Posted by .paul. View Post
    try this:

    vb.net Code:
    1. Imports <xmlns:ns="http://api.namecheap.com/xml.response">
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim xml = _
    7.         <?xml version="1.0" encoding="utf-8"?>
    8.         <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
    9.             <Errors/>
    10.             <Warnings/>
    11.             <RequestedCommand>namecheap.domains.check</RequestedCommand>
    12.             <CommandResponse Type="namecheap.domains.check">
    13.                 <DomainCheckResult Domain="domain1.com" Available="false"/>
    14.                 <DomainCheckResult Domain="domain2.com" Available="false"/>
    15.             </CommandResponse>
    16.             <Server>WEB1-SANDBOX1</Server>
    17.             <GMTTimeDifference>--4:00</GMTTimeDifference>
    18.             <ExecutionTime>2.391</ExecutionTime>
    19.         </ApiResponse>
    20.  
    21.         Dim nodes = From node In xml...<ns:CommandResponse>.<ns:DomainCheckResult> _
    22.                     Select New With { _
    23.                     .domain = node.@Domain, _
    24.                     .available = node.@Available}
    25.  
    26.         For Each node In nodes
    27.             ListView1.Items.Add(New ListViewItem(New String() {node.domain, node.available}))
    28.         Next
    29.  
    30.     End Sub
    31. End Class
    Yes, that works... But it needs to pull the information from the bellow and not a static file.

    This will check a list of keywords in listview1 for available domain names using the namecheap.com api. There isn't for vb2012/10/08 for using the namecheap api.

    webbrowser 1 will navigate to https://api.sandbox.namecheap.com/xm...om,domain2.com

    domain1.com and domain2.com will be replaced with all the contents from form1.listview1 and return the results to me.listview1

  4. #4

  5. #5
    Junior Member
    Join Date
    May 12
    Posts
    22

    Re: Parse xml to listview vbnet

    Quote Originally Posted by .paul. View Post
    change the declaration:

    Dim xml = _
    etc...

    to:

    Dim xml as xdocument = xdocument.load(url or filename)

    I Love you!

Posting Permissions

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