XML Reading
welcome to Game-Tuts.com - Register
Results 1 to 4 of 4

Thread: XML Reading

  1. #1
    VIP
    Join Date
    Dec 2009
    Location
    NY
    Posts
    514
    Thanks
    49
    Gamertag
    Modder23

    Default XML Reading

    What I am reading:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Employees>
    
    
    <Employee> 
    <Name>Andrew</Name>
    <Salary>9999</Salary> 
     </Employee>
    
    
    <Employee> 
    <Name>Joe</Name>
    <Salary>9998</Salary>    
     </Employee>
    
    
    <Employee> 
    <Name>Smith</Name>
    <Salary>9997</Salary>   
    </Employee>
    
    
    </Employees>
    How would I go about reading the child elements of ( Employee )?

  2. #2
    VIP
    Join Date
    Dec 2009
    Location
    UK
    Posts
    5,977
    Thanks
    692

    Default Re: XML Reading

    probably not the best way but,
    Code:
                XmlTextReader reader = new XmlTextReader("books.xml");
                while (reader.Read())
                {
                    if (reader.Name == "Name")
                    {
                        reader.Read();
                        string Name = reader.Value;
                    }
                    if (reader.Name == "Salary")
                    {
                        reader.Read();
                        string Salary = reader.Value;
                    }
                }
                reader.Close();
    Quote Originally Posted by Bran View Post
    We're also announcing that Modio will now follow a strict weekly update schedule where we will guarantee a new release on a weekly basis to keep Modio fresh and working perfectly.

  3. #3



    Join Date
    May 2009
    Location
    Nottingham, UK
    Age
    19
    Posts
    2,573
    Thanks
    554
    Gamertag
    iParadox NG

    Default Re: XML Reading

    Code:
                XmlDocument doc = new XmlDocument();
                doc.load(URL/PATH);
    try {
    
                 XmlNodeList nodes = doc.SelectNodes("Employees/Employee");
    
        foreach (XmlNode node in nodes) {
    
    
            string name = node.SelectSingleNode("Name").InnerText;
            string salary = node.SelectSingleNode("Salary").InnerText;
    
    
            ListView1.Items.Add(new ListViewItem(new string[] {name, salary}));
        }
    
    } catch (Exception ex) {
    
    }
    Last edited by Liam; 09-09-2011 at 10:15 AM.

  4. The Following User Says Thank You to Liam For This Useful Post:

    andrew74 (09-09-2011)

  5. #4
    VIP
    Join Date
    Dec 2009
    Location
    NY
    Posts
    514
    Thanks
    49
    Gamertag
    Modder23

    Default Re: XML Reading

    Quote Originally Posted by Liam View Post
    Code:
                XmlDocument doc = new XmlDocument();
                doc.load(URL/PATH);
    try {
    
                 XmlNodeList nodes = doc.SelectNodes("Employees/Employee");
    
        foreach (XmlNode node in nodes) {
    
    
            string name = node.SelectSingleNode("Name").InnerText;
            string salary = node.SelectSingleNode("Salary").InnerText;
    
    
            ListView1.Items.Add(new ListViewItem(new string[] {name, salary}));
        }
    
    } catch (Exception ex) {
    
    }
    Thanks thats what I was exactly looking for. Thank you very much!!!
    Last edited by andrew74; 09-09-2011 at 01:27 PM.


 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
visit GameTuts on these social networking sites