473,890 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: XML File Writing

Hi,

I'm working on the .NET Compact Framework, and I need a way in which i store
products in an xml file. Basically, when i add a product to the system, i
want to either add it to the XML file, (if it exists), or create a new XML
file with the item in it if the file doesn't exist.

Bearing in mind I'm on the compact framework, does anyone have any
suggestions how i can check the file ?

Many thanks.

This is my code so far.
using System;
using System.Xml;
using System.IO;
using System.Text;

namespace SaveExample
{

/// <summary>
/// Summary description for save.
/// </summary>

public class Save
{

public static void savefile()
{
XmlDocument xmldoc = new XmlDocument();
XmlElement playersnode;

try
{
StreamReader xmlfile = new StreamReader("p roducts.xml");
xmldoc.Load(xml file);
xmlfile.Close() ;

//get the products node
playersnode =xmldoc.CreateE lement("","prod ucts","");
}

catch(System.IO .FileNotFoundEx ception f){
//the file doesn't exist so we must create a new document

//let's add the XML declaration section
XmlNode xmlnode=xmldoc. CreateNode(XmlN odeType.XmlDecl aration,"","");

xmldoc.AppendCh ild(xmlnode);
XmlNode players = xmldoc.CreateNo de("","products ","");
xmldoc.AppendCh ild(products);

//let's add the root element
playersnode =xmldoc.CreateE lement("","prod ucts","");

}


//the products node

XmlElement product = xmldoc.CreateEl ement("product" );

//the id

XmlElement id = xmldoc.CreateEl ement("id");

XmlText id_value = xmldoc.CreateTe xtNode("id text");

id.AppendChild( id_value);

product.AppendC hild(id); //add the id to the product

xmldoc.Save("pr oducts.xml");

}

}

}

Nov 17 '05 #1
0 936

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

Similar topics

4
1944
by: eboogyman | last post by:
I have an HTML form with Firstname, lastname, address I want to save the firstname, lastname and address appended to a file in say results.txt, in the below format 1 entry per line... MyFirstname,MyLastname,MyAddress I know this is probebly easy, can someone help me with a code snippit that does this?
1
3731
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
36
3510
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a limit on this, max value you should be able to asign should be 0xffff // std::cout << test; // result = 0xffff //
2
2042
by: -D- | last post by:
I'm taking my first stab at using xml, so please bear with my novice questions and understanding of xml. I'm trying to create an xml file that holds all my website navigation. If I understand correctly, I can use xslt to create different menus from the xml file. What I'm trying to accomplish is to create a top menu bar, left navigation menu bar and sub header navigation bar. Then place the transformed xslt menus into user controls...
0
5584
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9978
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9822
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8016
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.