473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating and appending XML file

I'm creating a program which is to be used in soccer-cups. I'm going to use
a xml-file to store some values, the xml file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<player>
<playername></playername>
<matchesPlayed></matchesPlayed>
<matchesWon></matchesWon>
<matchesLost></matchesLost>
<goalsScored></goalsScored>
<goalsConceded></goalsConceded>
</player>
</root>

I have created an xmlhandler class, which is supposed to receive the data,
and update the xml file, but I'm stuck here..here thecode from the class:

class XMLHandler
{
private string pathTeams;
private string pathPlayers;
private XmlNodeList xmlnode;
private FileStream fs;
private XmlDocument xmldoc;

public XMLHandler()
{
pathTeams = Directory.GetCurrentDirectory() +
"\\XML\\Teams.xml";
pathPlayers = Directory.GetCurrentDirectory() +
"\\XML\\Players.xml";
}

public void WritePlayerNameToXml(ArrayList playerNames)
{
fs = new FileStream(pathPlayers, FileMode.Append,
FileAccess.Write,FileShare.Write);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
xmlnode = xmldoc.SelectNodes("(//playername)");
//foreach (XmlNode node in xmlnode)
//{
// sb.AppendLine(node.InnerText);
//}
for (int i = 0; i < playerNames.Count; i++)
{
//...
}
xmldoc.Save(fs);

}
}

Can someone please help me with some code to insert the player IF he does
not exist, and how can i update the statistics on the player IF he exists?
Nov 1 '06 #1
2 1320
Try to go from here:
http://msdn2.microsoft.com/en-us/library/k44daxya.aspx

chanmm

"Svein Erik" <se********@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
I'm creating a program which is to be used in soccer-cups. I'm going to
use a xml-file to store some values, the xml file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<player>
<playername></playername>
<matchesPlayed></matchesPlayed>
<matchesWon></matchesWon>
<matchesLost></matchesLost>
<goalsScored></goalsScored>
<goalsConceded></goalsConceded>
</player>
</root>

I have created an xmlhandler class, which is supposed to receive the data,
and update the xml file, but I'm stuck here..here thecode from the class:

class XMLHandler
{
private string pathTeams;
private string pathPlayers;
private XmlNodeList xmlnode;
private FileStream fs;
private XmlDocument xmldoc;

public XMLHandler()
{
pathTeams = Directory.GetCurrentDirectory() +
"\\XML\\Teams.xml";
pathPlayers = Directory.GetCurrentDirectory() +
"\\XML\\Players.xml";
}

public void WritePlayerNameToXml(ArrayList playerNames)
{
fs = new FileStream(pathPlayers, FileMode.Append,
FileAccess.Write,FileShare.Write);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
xmlnode = xmldoc.SelectNodes("(//playername)");
//foreach (XmlNode node in xmlnode)
//{
// sb.AppendLine(node.InnerText);
//}
for (int i = 0; i < playerNames.Count; i++)
{
//...
}
xmldoc.Save(fs);

}
}

Can someone please help me with some code to insert the player IF he does
not exist, and how can i update the statistics on the player IF he exists?

Nov 2 '06 #2

Svein Erik wrote:
I'm creating a program which is to be used in soccer-cups. I'm going to use
a xml-file to store some values, the xml file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<player>
<playername></playername>
<matchesPlayed></matchesPlayed>
<matchesWon></matchesWon>
<matchesLost></matchesLost>
<goalsScored></goalsScored>
<goalsConceded></goalsConceded>
</player>
</root>

I have created an xmlhandler class, which is supposed to receive the data,
and update the xml file, but I'm stuck here..here thecode from the class:

class XMLHandler
{
private string pathTeams;
private string pathPlayers;
private XmlNodeList xmlnode;
private FileStream fs;
private XmlDocument xmldoc;

public XMLHandler()
{
pathTeams = Directory.GetCurrentDirectory() +
"\\XML\\Teams.xml";
pathPlayers = Directory.GetCurrentDirectory() +
"\\XML\\Players.xml";
}

public void WritePlayerNameToXml(ArrayList playerNames)
{
fs = new FileStream(pathPlayers, FileMode.Append,
FileAccess.Write,FileShare.Write);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
xmlnode = xmldoc.SelectNodes("(//playername)");
//foreach (XmlNode node in xmlnode)
//{
// sb.AppendLine(node.InnerText);
//}
for (int i = 0; i < playerNames.Count; i++)
{
//...
}
xmldoc.Save(fs);

}
}

Can someone please help me with some code to insert the player IF he does
not exist, and how can i update the statistics on the player IF he exists?
Svein,

Perhaps instead to can read the XML file into a collection of player
objects, make whatever updates to whatever player object(s) need to be
done and then save the changes back to the XML file via serialization.

-Jay

Nov 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
2
by: matt | last post by:
Platform: Windows 2000, IE6, msxml 4 Language: Javascript, client-side <Problem>: I'm using the xmldom.load() function to load a .xml file from a remote server. But i require to constantly poll...
2
by: billrdio | last post by:
I am trying to make a JavaScript animation of real-time images - i.e. images that will periodically change on the server. The problem I am having is that the JavaScript animation I have created is...
16
by: Michael | last post by:
I have a data application in a2k that I need to create two fixed width text files and then combine them to a single file The first file is header information and the second is transaction data. ...
1
by: Darryl Neale | last post by:
I have been tasked with reviving an old database that stopped working about 3 years ago :( On one of the tabs is a list of links to other databases utilising the Hyperlink feature of MS Access...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
1
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
2
by: sarada purkait | last post by:
hii i have to write into a file from the start and then go on appending to it .. i tried using ( ios::out|ios::app) but by this the file keeps on appending every time i run the program and the...
3
by: HSXWillH | last post by:
I've looked through the site and not found what I'm looking for here. I am not code-versed or anything like that so my skills are rudimentary at best. I'm using Access 03 on a Windows Vista...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.