Protected Overridable Function GetFacebookFromReader(ByVal xmlResponse As String) As FacebookShareStatDetails
Dim xmlDoc As New XmlDocument()
Dim Facebook As FacebookShareStatDetails
Try
xmlDoc.LoadXml(xmlResponse)
If xmlDoc.SelectSingleNode("link_stat") IsNot Nothing And Not String.IsNullOrEmpty(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("total_count").InnerText) Then
Facebook = New FacebookShareStatDetails(CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("total_count").InnerText), CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("like_count").InnerText), CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("share_count").InnerText),
CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("click_count").InnerText))
Else
Facebook = Nothing
End If
Catch ex As Exception
Facebook = Nothing
End Try
Return Facebook
End Function
the problem I am having is that 'xmlDoc.SelectSingleNode("link_stat")' is alway nothing and all the children of it also.
Have you tried doing xmlDoc.SelectSingleNode("fql_query_response") and see if the parent level has to be selected first before you can navigate to the children of that?
If this answered your question, please mark as an answer so others will know too.
Member
110 Points
868 Posts
help parsing an xml response
Oct 14, 2010 02:23 PM|bcweed966|LINK
I have a xml response that I receive from facebook and I am having trouble parsing it. I am not an expert at XML....
this is the response I get and it is the value of 'xmlResponse' in the procedure:
<?xml version="1.0" encoding="UTF-8"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
<link_stat>
<like_count>0</like_count>
<total_count>0</total_count>
<share_count>0</share_count>
<click_count>0</click_count>
</link_stat>
</fql_query_response>
and I try parsing it like this:
Protected Overridable Function GetFacebookFromReader(ByVal xmlResponse As String) As FacebookShareStatDetails
Dim xmlDoc As New XmlDocument()
Dim Facebook As FacebookShareStatDetails
Try
xmlDoc.LoadXml(xmlResponse)
If xmlDoc.SelectSingleNode("link_stat") IsNot Nothing And Not String.IsNullOrEmpty(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("total_count").InnerText) Then
Facebook = New FacebookShareStatDetails(CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("total_count").InnerText), CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("like_count").InnerText), CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("share_count").InnerText), CLng(xmlDoc.SelectSingleNode("link_stat").SelectSingleNode("click_count").InnerText))
Else
Facebook = Nothing
End If
Catch ex As Exception
Facebook = Nothing
End Try
Return Facebook
End Function
the problem I am having is that 'xmlDoc.SelectSingleNode("link_stat")' is alway nothing and all the children of it also.
can anyone help? what am I doing wrong?
cheers
Participant
1125 Points
424 Posts
Re: help parsing an xml response
Oct 14, 2010 05:40 PM|Wyerarch|LINK
Have you tried doing xmlDoc.SelectSingleNode("fql_query_response") and see if the parent level has to be selected first before you can navigate to the children of that?
http://wyerarch.blogspot.com
All-Star
94120 Points
18111 Posts
Re: help parsing an xml response
Oct 17, 2010 10:40 PM|Decker Dong - MSFT|LINK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("XMLFile1.xml");
foreach (XmlNode item in doc.GetElementsByTagName("link_stat"))
{
foreach (XmlNode item1 in item.ChildNodes)
{
Console.WriteLine(item1.InnerText);
}
}
}
}
}