コード例 #1
0
        public static void BuildFromXml(XmlForm ProtoTypeXmlForm, string imageFolderPath)
        {
            XmlForm presidentForm     = new XmlForm("Presidential", ProtoTypeXmlForm.defaultFilePath);
            XmlForm congressionalForm = new XmlForm("Congressional", ProtoTypeXmlForm.defaultFilePath);
            XmlForm senateForm        = new XmlForm("Senate", ProtoTypeXmlForm.defaultFilePath);

            XmlNodeList raceNodes = ProtoTypeXmlForm.document.SelectNodes("//Race");

            XmlNodeList ReportingUnitNodes = ProtoTypeXmlForm.document.SelectNodes("//ReportingUnit");

            foreach (XmlNode node in ReportingUnitNodes)
            {
                node.DesolveNodeToParent();
            }

            foreach (XmlNode raceNode in raceNodes)
            {
                XmlNodeList candidateNodes = raceNode.SelectNodes("./Candidate");
                double      totalRaceVotes = GetTotalVotesFromCandidates(candidateNodes);
                raceNode.AddAttribute("TotalVotes", totalRaceVotes.ToString("N0"));
                AddVotePercentToCandidates(candidateNodes, totalRaceVotes);

                string officeName = raceNode.Attributes["OfficeName"].Value;

                switch (officeName)
                {
                case "President":

                    XmlNode     presidentRaceNode       = presidentForm.ImportNode(raceNode);
                    XmlNodeList presidentCandidateNodes = presidentRaceNode.SelectNodes("./Candidate");
                    AddImageLinksToCandidates(presidentCandidateNodes, imageFolderPath);
                    break;

                case "U.S. House":

                    string  currentStatePostal = raceNode.Attributes["StatePostal"].Value;
                    XmlNode stateNode          = congressionalForm.MainNode.SelectSingleNode("./State[@StateCode='" + currentStatePostal + "']");

                    if (stateNode == null)
                    {
                        stateNode = congressionalForm.CreateNode("State");
                        stateNode.AddAttribute("StateCode", currentStatePostal);
                        stateNode.AddAttribute("Name", raceNode.Attributes["Name"].Value);
                    }
                    XmlNode congressRaceNode = congressionalForm.ImportNode(raceNode, stateNode);
                    break;

                case "U.S. Senate":
                    XmlNode senateRaceNode = senateForm.ImportNode(raceNode);
                    break;

                default:
                    break;
                }
            }

            presidentForm.save();
            senateForm.save();
            congressionalForm.save();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Kevinw721/RSSInteraceApp
        private void saveXmlToPrototype()
        {
            string myXML = pullXMLFromURL(createFinalPullString());

            if (myXML != null)
            {
                ProtoTypeXmlForm.LoadXml(myXML);
                ProtoTypeXmlForm.save(myFilePath);
            }
        }