Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Problem with Reading XML (http://www.xtremevbtalk.com/-net-general/328606-reading-xml.html)

digitaldrew 03-24-2017 03:58 PM

Problem with Reading XML
 
Hey everyone. I hope I can get some help here since I'm not really sure if I am doing this the right way.

I am sending a request that includes 4 domains which I would like to check the availability of. The response I receive (below) contains each domain with different responses that may be received. I am trying to figure out the best way to go through the XML and properly check for which ones come back as Available and which ones come back as Not Available.

Code:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
      <ns7:SgndCommandResponse xmlns:ns7="http://www.nic.es/sgnd/schemas" xmlns:ns10="http://www.nic.es/sgnd/schemas-movement" xmlns:ns11="http://www.nic.es/sgnd/schemas-invoice" xmlns:ns12="http://www.nic.es/sgnd/schemas-tradeaction" xmlns:ns13="http://www.nic.es/sgnd/schemas-ownershipcertificate" xmlns:ns14="http://www.nic.es/sgnd/schemas-statistic" xmlns:ns2="http://www.nic.es/sgnd/schemas-domain" xmlns:ns3="http://www.nic.es/sgnd/schemas-order" xmlns:ns4="http://www.nic.es/sgnd/schemas-contact" xmlns:ns5="http://www.nic.es/sgnd/schemas-host" xmlns:ns6="http://www.nic.es/sgnd/schemas-dnssec" xmlns:ns8="http://www.nic.es/sgnd/schemas-inbox" xmlns:ns9="http://www.nic.es/sgnd/schemas-extraordinarycancelation">
        <ns7:DomainCreateResponse>
            <ns2:Name>domainavailable1.es</ns2:Name>
            <ns2:Name>domainavailable2.es</ns2:Name>
            <ns2:Autorenew>false</ns2:Autorenew>
            <ns2:Creation>2016-11-24T15:07:05.364+01:00</ns2:Creation>
            <ns2:Expiration>2017-11-24T15:07:05.364+01:00</ns2:Expiration>
            <ns2:Order>
              <ns3:OrderId>553905</ns3:OrderId>
              <ns3:OrderType>1</ns3:OrderType>
              <ns3:State>DMOK</ns3:State>
              <ns3:StateDescription>Efectuada</ns3:StateDescription>
              <ns3:Creation>2016-11-24T15:07:05.398+01:00</ns3:Creation>
              <ns3:Reference>AD-ES-553905-F5</ns3:Reference>
              <ns3:DomainData>
                  <ns2:Name>domainavailable1.es</ns2:Name>
              </ns3:DomainData>
            </ns2:Order>
            <ns2:Order>
              <ns3:OrderId>553906</ns3:OrderId>
              <ns3:OrderType>1</ns3:OrderType>
              <ns3:State>DMOK</ns3:State>
              <ns3:StateDescription>Efectuada</ns3:StateDescription>
              <ns3:Creation>2016-11-24T15:07:05.603+01:00</ns3:Creation>
              <ns3:Reference>AD-ES-553906-F5</ns3:Reference>
              <ns3:DomainData>
                  <ns2:Name>domainavailable2.es</ns2:Name>
              </ns3:DomainData>
            </ns2:Order>
            <ns2:NotIncluded>
              <ns2:ErrorCause id="3019">
                  <ns2:Name>notavailable.es</ns2:Name>
              </ns2:ErrorCause>
              <ns2:ErrorCause id="3001">
                  <ns2:Name>domain.incorrect</ns2:Name>
              </ns2:ErrorCause>
            </ns2:NotIncluded>
        </ns7:DomainCreateResponse>
        <ns7:ReturnCode>1000</ns7:ReturnCode>
        <ns7:ServerData>
            <ns7:Timestamp>2016-11-24T15:07:05.767+01:00</ns7:Timestamp>
            <ns7:ClientID>CLIENT-ID-AR-CHECKLIST</ns7:ClientID>
            <ns7:ServerID>1479996425767</ns7:ServerID>
        </ns7:ServerData>
      </ns7:SgndCommandResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The way I am currently trying to handle this is by looking for "ns2:Order" tags and then pulling the domain from each of those. As you can see above (domainavailable1.es) and (domainavailable2.es) are the two available domains here.

Next, I try to loop through and look for "ns2:NotIncluded" tags and pull the domain from there if it has an ErrorCause id of "3019".. As you can see above (notavailable.es) is the not available domain here.

Below is the complete code I am using to try and read through the XML above and pull the proper domain with the proper status (available) or (not available), but it does not seam to be working properly. Is there a better way I could be doing this?

Code:

                        'READ RESPONSE WITH MULTIPLE DOMAINS
                        Dim doc As New XmlDocument()
                        doc.Load(WebResponse)
                        txtLog.AppendText(WebResponse & vbCrLf)

                        'HANDLE AVAILABLE DOMAINS
                        Dim nodelist As XmlNodeList = doc.GetElementsByTagName("ns2:Order")
                        For Each node As XmlElement In nodelist
                            Dim nodeDomain As String = String.Empty
                            nodeDomain = node("ns2:Name").InnerText
                            txtLog.AppendText(nodeDomain & " SUCCESS ...via ESNIC THREAD(1) at: " & TimeOfDay & vbCrLf)
                            removeDomain(nodeDomain)
                        Next

                        'HANDLE NOT AVAILABLE DOMAINS
                        Dim nodelist2 As Xml.XmlNodeList = doc.GetElementsByTagName("ns2:NotIncluded")
                        For Each cat As Xml.XmlElement In nodelist2
                            Dim nodeDomain2 As String = String.Empty
                            Dim sResult As String = cat.GetAttribute("id")
                            nodeDomain2 = cat("ns2:Name").Value
                            If sResult = "3019" Then
                                txtLog.AppendText(nodeDomain2 & " NOT AVAILABLE ...via ESNIC THREAD(1) at: " & TimeOfDay & vbCrLf)
                            Else
                                txtLog.AppendText(nodeDomain2 & " UNKNOWN ERROR (ID: " & sResult & ") ...via ESNIC THREAD(1) at: " & TimeOfDay & vbCrLf)
                            End If
                        Next

Thanks in advance!


All times are GMT -6. The time now is 10:55 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.