You are viewing our Forum Archives. To view or take place in current topics click here.
Need help reading XML nodes in vb.net
Posted:

Need help reading XML nodes in vb.netPosted:

OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
I am trying to read some xml file that contains the username of the current user on my site and display it in a label text in a form.

<member>
<display-name>Omit Zz</display-name>
<permission-id type="integer">507910</permission-id>
<rank-id nil="true"/>
<signature/>
<sig-disabled type="boolean">false</sig-disabled>
</member>


Here is the url: [ Register or Signin to view external links. ]

Here is the code used on form load
Dim xmlData As New XmlDocument
        Try
            xmlData.Load("http://xpro.shivtr.com/my_account/member.xml")
        Catch ex As Exception

        End Try
        Dim xnod As XmlNode = xmlData.DocumentElement
        ReadXML(xnod)


and here is the sub for ReadXML

Private Sub ReadXML(ByVal xnod As XmlNode)
        Dim xnodWorking As XmlNode
        If Len(xnod.Value) > 0 Then
            Try
                If xnod.ParentNode.LocalName = "display-name" Then
                    Membership.Text = xnod.Value
                End If
            Catch ex As Exception
            End Try
        End If
        If xnod.HasChildNodes Then
            xnodWorking = xnod.FirstChild
            Do Until IsNothing(xnodWorking)
                ReadXML(xnodWorking)
                xnodWorking = xnodWorking.NextSibling
            Loop
        End If
    End Sub


When I run this code I get this error
[ Register or Signin to view external links. ]

I am not exactly sure why this isn't working. I don't know much about xml but I used this same code to loop through nodes to get XBL gamertag info for a GT checker and that works perfectly. Any help guys?
#2. Posted:
Bighair
  • Powerhouse
Status: Offline
Joined: Sep 26, 201013Year Member
Posts: 401
Reputation Power: 17
Status: Offline
Joined: Sep 26, 201013Year Member
Posts: 401
Reputation Power: 17
HAve you got skype? I can help you but there is alot of explaining to do an would be easier on skype? Whatsyour Skype name?
#3. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Bighair wrote HAve you got skype? I can help you but there is alot of explaining to do an would be easier on skype? Whatsyour Skype name?

Awesome my Skype is Pro.RPGz
#4. Posted:
Z61
  • V5 Launch
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Just do
.isEmpty()
that should solve your problem.
#5. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Z61 wrote Just do
.isEmpty()
that should solve your problem.


I assume you are talking about if Len(xnod.value) > 0 then
which that doesn't work.
#6. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
OmitZz wrote
Z61 wrote Just do
.isEmpty()
that should solve your problem.


I assume you are talking about if Len(xnod.value) > 0 then
which that doesn't work.



xnod.Value will throw an exception if the Node Type is not supposed to have a value.

You need to check the NodeType before assuming the value is present.


If xnod.NodeType = XmlNodeType.Text Then
   Try
      If xnod.ParentNode.LocalName = "display-name" Then
         Membership.Text = xnod.Value
      End If
   Catch ex As Exception
   End Try
End If


This is a very brief bit of code and you may need to do more validation.
#7. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201211Year Member
Posts: 68
Reputation Power: 2
Imp wrote
OmitZz wrote
Z61 wrote Just do
.isEmpty()
that should solve your problem.


I assume you are talking about if Len(xnod.value) > 0 then
which that doesn't work.



xnod.Value will throw an exception if the Node Type is not supposed to have a value.

You need to check the NodeType before assuming the value is present.


If xnod.NodeType = XmlNodeType.Text Then
   Try
      If xnod.ParentNode.LocalName = "display-name" Then
         Membership.Text = xnod.Value
      End If
   Catch ex As Exception
   End Try
End If


This is a very brief bit of code and you may need to do more validation.


[ Register or Signin to view external links. ]

I have ran into this with like 5 codes I've tried. Can I get past this?
#8. Posted:
5FDP_Jekyll
  • V5 Launch
Status: Offline
Joined: May 27, 201113Year Member
Posts: 2,048
Reputation Power: 100
Status: Offline
Joined: May 27, 201113Year Member
Posts: 2,048
Reputation Power: 100
The only thing i can think of is that maybe it can not connect to the site, or you may need to change the permissions of the file, so that the program can read it.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.