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:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year 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.
Here is the url: [ Register or Signin to view external links. ]
Here is the code used on form load
and here is the sub for ReadXML
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?
<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:
Status: Offline
Joined: Sep 26, 201014Year Member
Posts: 401
Reputation Power: 17
Status: Offline
Joined: Sep 26, 201014Year 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?
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year 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
- 0useful
- 0not useful
#4. Posted:
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 that should solve your problem.
.isEmpty()
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Z61 wrote Just dothat should solve your problem..isEmpty()
I assume you are talking about if Len(xnod.value) > 0 then
which that doesn't work.
- 0useful
- 0not useful
#6. Posted:
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 wroteZ61 wrote Just dothat should solve your problem..isEmpty()
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.
- 0useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Imp wroteOmitZz wroteZ61 wrote Just dothat should solve your problem..isEmpty()
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?
- 0useful
- 0not useful
#8. Posted:
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.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.