Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 25th, 2006, 10:33 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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);
                                }
                            }
                        }
                    }
                }


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading XML through ASP jeffm_22 Classic ASP XML 3 June 11th, 2010 07:02 AM
problem reading a value from an xml mrjoka XML 14 June 8th, 2007 10:48 AM
reading a XML file connect2sandep XML 1 December 14th, 2006 04:50 AM
reading a XML file connect2sandep General .NET 0 December 13th, 2006 02:10 PM
Reading XML datastream realgone_ Classic ASP XML 5 September 22nd, 2004 01:17 PM





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