View Single Post
  #6 (permalink)  
Old January 7th, 2008, 04:30 PM
Sojan80 Sojan80 is offline
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts

I've got the loop through the XML working almost exactly like I want it. Almost. I need some help figuring out a problem with the recursion.

For elements in the XML where there is an attribute assigned and child nodes:
  <ACTIVITY_LEADERSHIP>President; Oration Trophy 2007; Midwest Debate Champion 2006</ACTIVITY_LEADERSHIP>
what I want to do is grab the value of the id attribute and then loop through the child nodes inserting each child node into the database like this:
FILE_DATE = File Date from XML File
TAG_ID = 1
TAG_VALUE = Debate Club
and so on for each child node. However I do not want the ACTIVITIES Tag itself entered at all.

If there is no attribute assigned I still want to insert it into the database like above, but the tag id is set 0;

Here's the Sample XML:
<?xml version="1.0"?>
<DataFile xmlns:xsi="" xmlns:xsd="">
    <FileDate>10/24/2007 9:25:52 AM</FileDate>
    <FileVersion>0.1 - alpha</FileVersion>
      <ACTIVITY_STATEMENT>The debate club is something I feel very strongly about. I am a very good orator; I primarily argue through repetition, and I invariably convince everybody I speak to. I am a very good orator; I primarily argue through repetition, and I invariably convince everybody I speak to. I am a very good orator; I primarily argue through repetition, and I invariably convince everybody I speak to. I am a very good orator; I primarily argue through repetition, and I invariably convince everybody I speak to. Aren't you convinced by now?</ACTIVITY_STATEMENT>
      <ACT_2_DATE />

      <ENRICHMENT_STATEMENT>While young people embrace the Web with real or virtual friends, and their mobile phone is never far away, relatively few like technology, and those that do like technology tend to be in Brazil, India and China, according to a survey.

Only a handful think of technology as a concept, and just 16 percent use terms like "social networking," said two combined surveys covering 8- to 24-year-olds published on Tuesday by Microsoft and Viacom unit MTV Networks, which includes Nickelodeon.

"Young people don't see tech as a separate entity--it's an organic part of their lives," said Andrew Davidson, vice president at MTV Networks International.

"Talking to them about the role of technology in their lifestyle would be like talking to kids in the 1980s about the role the park swing or the telephone played in their social lives--it's invisible," Davidson said.

The surveys involved 18,000 young people in 16 countries, including the United Kingdom, the United States, China, Japan, Canada and Mexico.

Terms most frequently used by the young when talking about technology related to accessing content for free, notably "download and "burn."

The surveyors found that the average Chinese computer user has 37 online friends they have never met. Indian youth are most likely to see mobile phones as a status symbol, while a third of U.K. and U.S. teenagers say they cannot live without game consoles.

"The way each technology is adopted and adapted throughout the world depends as much on local cultural and social factors as on the technology itself," Davidson said.

For example, the key digital device for Japan's young is the mobile phone because of the privacy and portability it offers those who live in small homes with limited privacy.

The survey found that Japanese children ages 8 to 14 have only one online friend they have not met, compared to a global average of five. Some 93 percent of Chinese computer users in that age range have more than one friend online they have never met.

Davidson said this was encouraging those ages 8 to 14 in China to select online content over television--a trend not seen in any other market in that age group.

The changes in how the youth market engages with technology is keenly followed by advertisers and content providers. For parents worried about what their children are getting up to amid the wave of gadgets, little has changed in a generation.

The surveyors found that the most popular activities among those in the 8-to-14 bracket are watching TV, listening to music and being with friends. The rankings for those older was similar, though listening to music was top.</ENRICHMENT_STATEMENT>

      <STATEMENT>Microsoft is planning to ship its next major version of Windows--known internally as version "7"--within roughly three years, CNET has learned.

The company discussed Windows 7 on Thursday at a conference for its field sales force in Orlando, Fla., according to sources close to the company.

While the company provided few details, Windows 7, the next client version of the operating system, will be among the steps taken by Microsoft to establish a more predictable release schedule, according to sources. The company plans a more "iterative" process of information disclosure to business customers and partners, sources said.

Windows Vista, the oft-delayed most recent release of Windows, shipped to businesses in November and to consumers in January after more than five years of development. Vista's gestation period was marked by shifting product details as internal priorities changed and problems arose with development.

Like Vista, Windows 7 will ship in consumer and business versions, and in 32-bit and 64-bit versions. The company also confirmed that it is considering a subscription model to complement Windows, but did not provide specifics or a time frame.

Next up on Microsoft's agenda is Service Pack 1 for Windows Vista, which is expected before year's end.

The discussion of Windows' future isn't surprising, given that Microsoft has been criticized by business customers for delays related to Vista. Many business customers pay for Microsoft's software under a license agreement called Software Assurance.

Windows 7 was previously known by the code name Vienna. A Microsoft representative confirmed that Windows 7 is the internal code name for the next client release of Windows. The details were released "as part of our ongoing outreach to enterprise customers and partners, Microsoft has begun sharing plans for how they will continue to deliver value to businesses in the future…Software Assurance customers in particular," a representative said in a statement via e-mail.

"Microsoft is scoping Windows 7 development to a three-year time frame, and then the specific release date will ultimately be determined by meeting the quality bar," according to the representative.</STATEMENT>

      <ACTIVITIES id="1">
        <ACTIVITY>Debate Club</ACTIVITY>
        <ACTIVITY_LEADERSHIP>President; Oration Trophy 2007; Midwest Debate Champion 2006</ACTIVITY_LEADERSHIP>
      <ACTIVITIES id="2">
        <ACTIVITY>Marching Band</ACTIVITY>
      <ACTIVITIES id="3">
        <ACTIVITY>Jazz Band</ACTIVITY>
      <APPLICANT_EMAIL id="1">
      <COLLEGE1COURSE id="1">
        <COLLEGE1COURSE_TITLE>Intro to Computer Graphics</COLLEGE1COURSE_TITLE>
      <COLLEGE1COURSE id="2">
      <EMPLOYMENT id="1">
        <EMPLOY_EMPLOYER>Madison Computer Works</EMPLOY_EMPLOYER>
        <EMPLOY_TO_DATE />
      <EMPLOYMENT id="2">

and here's my C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using AISUtilLib;
using System.Data.OracleClient;

namespace XmlTest3
    class Program
        static void Main(string[] args)

            // Declare some variables to hold values for processing
            String fileDate = String.Empty;
            String savedApplicationId = String.Empty;
            String eTagName = String.Empty;
            String eValue = String.Empty;
            String eUserName = "XmlTest3";

            // Set nodeAttribute to 0 by default
            // This means there were no attributes found
            String eTagId = "0";

            string xmlPath = @"DataFile2.xml";
            XmlDocument doc = new XmlDocument();

                // Load the Xml from the file
                doc.PreserveWhitespace = false;

                // Get the file Date before we do anything else
                fileDate = doc.SelectSingleNode("//FileDate").InnerText.ToString();
                //Console.WriteLine("File Date: {0}", fileDate);

                // Get all the Application nodes in the file by using SelectNodes
                foreach (XmlNode appNode in doc.SelectNodes("//Application"))
                    /* At this point we should have a collection of all the
                     * application nodes in the file. We also know that
                     * Application has a ChildNodes collection associated with
                     * it. */

                    // Get the savedApplicationId for this Application node
                    savedApplicationId = appNode.SelectSingleNode("//SavedApplicationID").InnerText.ToString();

                    // Now we need to loop through all the child nodes of Application
                    foreach (XmlNode childNode in appNode.ChildNodes)
                        // This will test to see that the local name of childNode
                        // is not one we want to exclude / skip.

                        switch (childNode.LocalName)
                            case "UniqueHash": // We want to skip over this field entirely
                            case "ACTIVITY_STATEMENT": // We want to skip over this field entirely
                            case "ENRICHMENT_STATEMENT": // We want to skip over this field entirely
                            case "STATEMENT": // We want to skip over this field entirely
                                eTagName = childNode.LocalName.ToString();
                                eValue = childNode.InnerText.ToString();

                                // Check to see if the childNode has an attribute
                                // and process accordingly
                                XmlAttributeCollection attrs = childNode.Attributes;
                                foreach (XmlAttribute attr in attrs)
                                    // We have an attribute and assign the value
                                    eTagId = attr.Value.ToString();

                                    // We need to do a for each for each of the child nodes
                                    // returning tag name, value and calling save
                                    foreach (XmlNode node in childNode.ChildNodes)
                                        eTagName = node.LocalName.ToString();
                                        eValue = node.InnerText.ToString();
                                        Save(fileDate, savedApplicationId, eTagName, eTagId, eValue, eUserName);

                                //eTagName = childNode.LocalName.ToString();
                                //eValue = childNode.InnerText.ToString();
                                Save(fileDate, savedApplicationId, eTagName, eTagId, eValue, eUserName);




            catch (XmlException xmlEx)
                Console.Write("Xml Exception: " + xmlEx.Message);
            catch (Exception ex)
                Console.Write("Exception: " + ex.Message);

        }// end static void Main
        public static void Save(string fileDate, string savedApplicationId, string eTagName, string eTagId, string eValue, string eUserName)
            String eAppSql = String.Empty;
            //eAppSql = "INSERT INTO " ;
            eAppSql = "File Date: " + fileDate.ToString() + " Saved App Id: " + savedApplicationId.ToString() + " Tag Name: " + eTagName.ToString() + " Tag Id: " + eTagId.ToString() + " Value: " + eValue.ToString();

            // Establish Connection to Oracle Datastore
            //OracleConnection oConn = new OracleConnection(AISUtilLib.AISConnStrOra._f_SIS_U WSPOL_PUB("Test"));


        } //end public static void Save


I can't quite figure out where my loop is going wrong. How should I be setting up the loops so they work like I want?

Reply With Quote