GetVertexCount ( XmlDocument oGraphMLXmlDocument ) { Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); Int32 iVertexCount = 0; XmlNode oXmlNode; XmlNamespaceManager oXmlNamespaceManager = GraphMLXmlDocument.CreateXmlNamespaceManager( oGraphMLXmlDocument, "g"); if (XmlUtil2.TrySelectSingleNode(oGraphMLXmlDocument, "g:graphml/g:graph/g:node", oXmlNamespaceManager, out oXmlNode)) { while (oXmlNode != null) { if (oXmlNode.Name == "node") { iVertexCount++; } oXmlNode = oXmlNode.NextSibling; } } return(iVertexCount); }
AppendAllStatisticGraphMLAttributeValues ( String sUserName, XmlNode oVertexXmlNode, GraphMLXmlDocument oGraphMLXmlDocument, RequestStatistics oRequestStatistics ) { Debug.Assert(!String.IsNullOrEmpty(sUserName)); Debug.Assert(oVertexXmlNode != null); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oRequestStatistics != null); AssertValid(); XmlDocument oXmlDocument; XmlNamespaceManager oXmlNamespaceManager; // Some of the statistics are available in the user's profile. String sUrl = "http://gdata.youtube.com/feeds/api/users/" + EncodeUrlParameter(sUserName); if (TryGetXmlDocument(sUrl, oRequestStatistics, out oXmlDocument, out oXmlNamespaceManager)) { AppendYouTubeDateGraphMLAttributeValue(oXmlDocument, "a:entry/a:published/text()", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, JoinedDateUtcID); AppendStringGraphMLAttributeValue(oXmlDocument, "a:entry/media:thumbnail/@url", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, NodeXLGraphMLUtil.VertexImageFileID); XmlNode oStatisticsXmlNode; if (XmlUtil2.TrySelectSingleNode(oXmlDocument, "a:entry/yt:statistics", oXmlNamespaceManager, out oStatisticsXmlNode)) { AppendInt32GraphMLAttributeValue(oStatisticsXmlNode, "@videoWatchCount", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, VideosWatchedID); AppendInt32GraphMLAttributeValue(oStatisticsXmlNode, "@subscriberCount", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, SubscribersID); } } // The remaining statistics must be obtained from the totalResults // XML node within documents obtained from other URLs. const String TotalResultsXPath = "a:feed/openSearch:totalResults/text()"; sUrl = GetFriendsOrSubscriptionsUrl(sUserName, true) + "?max-results=1"; AppendInt32GraphMLAttributeValue(sUrl, TotalResultsXPath, oGraphMLXmlDocument, oRequestStatistics, oVertexXmlNode, FriendsID); sUrl = GetFriendsOrSubscriptionsUrl(sUserName, false) + "?max-results=1"; AppendInt32GraphMLAttributeValue(sUrl, TotalResultsXPath, oGraphMLXmlDocument, oRequestStatistics, oVertexXmlNode, SubscriptionsID); sUrl = "http://gdata.youtube.com/feeds/api/users/" + EncodeUrlParameter(sUserName) + "/uploads?max-results=1"; AppendInt32GraphMLAttributeValue(sUrl, TotalResultsXPath, oGraphMLXmlDocument, oRequestStatistics, oVertexXmlNode, VideosUploadedID); }