예제 #1
0
        public WolframAlphaQueryResult LoadResponse(String Response)
        {
            XmlDocument             Document = new XmlDocument();
            WolframAlphaQueryResult Result   = null;

            try
            {
                Document.LoadXml(Response);
                Result = LoadResponse(Document);
            }
            catch
            {
            }
            Document = null;

            return(Result);
        }
예제 #2
0
        public WolframAlphaQueryResult LoadResponse(XmlDocument Response)
        {
            System.Threading.Thread.Sleep(1);

            XmlNode MainNode = Response.SelectNodes("/queryresult")[0];

            WA_QueryResult              = new WolframAlphaQueryResult();
            WA_QueryResult.Success      = Convert.ToBoolean(MainNode.Attributes["success"].Value);
            WA_QueryResult.ErrorOccured = Convert.ToBoolean(MainNode.Attributes["error"].Value);
            WA_QueryResult.NumberOfPods = Convert.ToInt32(MainNode.Attributes["numpods"].Value);
            WA_QueryResult.Timing       = Convert.ToDouble(MainNode.Attributes["timing"].Value.Replace(".", ","));
            WA_QueryResult.TimedOut     = MainNode.Attributes["timedout"].Value;
            WA_QueryResult.DataTypes    = MainNode.Attributes["datatypes"].Value;
            WA_QueryResult.Pods         = new List <WolframAlphaPod>();

            foreach (XmlNode Node in MainNode.SelectNodes("pod"))
            {
                System.Threading.Thread.Sleep(1);

                WolframAlphaPod Pod = new WolframAlphaPod();

                Pod.Title           = Node.Attributes["title"].Value;
                Pod.Scanner         = Node.Attributes["scanner"].Value;
                Pod.Position        = Convert.ToInt32(Node.Attributes["position"].Value);
                Pod.ErrorOccured    = Convert.ToBoolean(Node.Attributes["error"].Value);
                Pod.NumberOfSubPods = Convert.ToInt32(Node.Attributes["numsubpods"].Value);
                Pod.SubPods         = new List <WolframAlphaSubPod>();

                foreach (XmlNode SubNode in Node.SelectNodes("subpod"))
                {
                    System.Threading.Thread.Sleep(1);

                    WolframAlphaSubPod SubPod = new WolframAlphaSubPod();
                    SubPod.Title = SubNode.Attributes["title"].Value;

                    foreach (XmlNode ContentNode in SubNode.SelectNodes("plaintext"))
                    {
                        System.Threading.Thread.Sleep(1);
                        SubPod.PodText = ContentNode.InnerText;
                    }

                    foreach (XmlNode ContentNode in SubNode.SelectNodes("img"))
                    {
                        System.Threading.Thread.Sleep(1);

                        WolframAlphaImage Image = new WolframAlphaImage();
                        Image.Location  = new Uri(ContentNode.Attributes["src"].Value);
                        Image.HoverText = ContentNode.Attributes["alt"].Value;
                        Image.Title     = ContentNode.Attributes["title"].Value;
                        Image.Width     = Convert.ToInt32(ContentNode.Attributes["width"].Value);
                        Image.Height    = Convert.ToInt32(ContentNode.Attributes["height"].Value);
                        SubPod.PodImage = Image;
                    }

                    Pod.SubPods.Add(SubPod);
                }

                WA_QueryResult.Pods.Add(Pod);
            }

            return(WA_QueryResult);
        }