p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   Reading XML (http://p2p.wrox.com/showthread.php?t=45689)

evidica July 25th, 2006 10:33 AM

Reading XML
 
I am trying to read in the following XML:

Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <weather>
  <timestamp zone="GMT">07/25/2006 11:27</timestamp>
- <forecast>
  <citycode>CFV</citycode>
- <day>
  <name>Tuesday</name>
  <icon>02</icon>
  <high unit="F">96</high>
  <low unit="F">76</low>
  <phrase>Mostly sunny</phrase>
  </day>
- <day>
  <name>Wednesday</name>
  <icon>03</icon>
  <high unit="F">97</high>
  <low unit="F">76</low>
  <phrase>Partly sunny and hot</phrase>
  </day>
- <day>
  <name>Thursday</name>
  <icon>03</icon>
  <high unit="F">94</high>
  <low unit="F">73</low>
  <phrase>Some sun</phrase>
  </day>
- <day>
  <name>Friday</name>
  <icon>03</icon>
  <high unit="F">92</high>
  <low unit="F">73</low>
  <phrase>Partial sunshine</phrase>
  </day>
- <day>
  <name>Saturday</name>
  <icon>03</icon>
  <high unit="F">93</high>
  <low unit="F">70</low>
  <phrase>Partly sunny</phrase>
  </day>
- <day>
  <name>Sunday</name>
  <icon>03</icon>
  <high unit="F">97</high>
  <low unit="F">71</low>
  <phrase>Partly sunny</phrase>
  </day>
- <day>
  <name>Monday</name>
  <icon>02</icon>
  <high unit="F">95</high>
  <low unit="F">74</low>
  <phrase>Mostly sunny</phrase>
  </day>
  </forecast>
  <copyright>Copyright AccuWeather, Inc. 2006</copyright>
  </weather>

I am able to get city code and then enter the child nodes. My problem arises that I cannot add the data to the database until I get the name field in as well. How would I pull the name text before I enter my loop? Here is what I have:

Code:

string xmlgroup = "";
                string locationID = "";
                string dayName = "";
                //Loop through all of the communities

                foreach (XmlNode node in SevenDay)
                {

                    if (node.ChildNodes.Count > 0)
                    {
                        XmlNodeList childnodes = node.ChildNodes;

                        foreach (XmlNode node2 in childnodes)
                        {

                            if (node2.ChildNodes.Count > 0)
                            {
                                //Set the child node list
                                XmlNodeList daychildnodes = node2.ChildNodes;

                                //Save all data to the databas

                                    locationID= node2.FirstChild.InnerText;
                                    Console.WriteLine("LocationID: "+locationID);

//I NEED TO GET THE dayname variable assigned here from the name field.
                            InjectSevenToDatabase(0, locationID, null, null, dayname);
                                foreach (XmlNode chNode in daychildnodes)
                                {
                                    InjectSevenToDatabase(1, locationID, chNode.Name, chNode.InnerText, dayname);
                                }
                            }
                        }
                    }
                }



All times are GMT -4. The time now is 04:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.