473,792 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Basic XML File Creation / Editing

Is there a basic guide on Xml document creation and editing (simpler
than the MSDN docs). Say I want to create a file containing the
following:

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
</Files>
I know how you can use XMLTextWriter to do this:

XmlTextWriter xtw = new XmlTextWriter(" myfile.xml",
System.Text.Enc oding.UTF8);
xtw.WriteStartD ocument(true);
xtw.WriteStartE lement("Files") ;
xtw.WriteStartE lement("File");
xtw.WriteElemen tString("Text", txtName.Text);
xtw.WriteElemen tString("Name", FileName);
xtw.WriteEndEle ment();
xtw.WriteEndEle ment();
xtw.WriteEndDoc ument();
xtw.Close();

However, how do you check if the file exists, and append to it instead
of overwriting?

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
</Files>

Also, I may wish to delete an existing entry, under certain
circumstances (file deleted from disk):

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
</Files>

And also, prevent duplicate entries being added (re uploading a file).

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
</Files>

I know there is a class library at the code project that writes to XML
files (http://www.codeproject.com/csharp/ReadWriteXmlIni.asp), but it
does far more than I need and I would rather learn how to do it myself
than rely on a third party library.

I would also like to read the xml from the file and then display in a
page (links to documents, Text is the link text, Name is the file
name). Bound to a repeater, also displaying file size by querying the
file system.

Nov 12 '05 #1
1 1687
you mean like netscape 1992
with document.write in the browser ?

=============== ============

NO !
Just look at the tripple verbosity

of the object "XmlTextWri ter"




<sa*********@gm ail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Is there a basic guide on Xml document creation and editing (simpler
than the MSDN docs). Say I want to create a file containing the
following:

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
</Files>
I know how you can use XMLTextWriter to do this:

XmlTextWriter xtw = new XmlTextWriter(" myfile.xml",
System.Text.Enc oding.UTF8);
xtw.WriteStartD ocument(true);
xtw.WriteStartE lement("Files") ;
xtw.WriteStartE lement("File");
xtw.WriteElemen tString("Text", txtName.Text);
xtw.WriteElemen tString("Name", FileName);
xtw.WriteEndEle ment();
xtw.WriteEndEle ment();
xtw.WriteEndDoc ument();
xtw.Close();

However, how do you check if the file exists, and append to it instead
of overwriting?

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
</Files>

Also, I may wish to delete an existing entry, under certain
circumstances (file deleted from disk):

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
</Files>

And also, prevent duplicate entries being added (re uploading a file).

<?xml version="1.0" encoding="utf-8" standalone="yes "?>
<Files>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
<File>
<Text>Test 2</Text>
<Name>Test2.htm l</Name>
</File>
<File>
<Text>Test</Text>
<Name>Test.html </Name>
</File>
</Files>

I know there is a class library at the code project that writes to XML
files (http://www.codeproject.com/csharp/ReadWriteXmlIni.asp), but it
does far more than I need and I would rather learn how to do it myself
than rely on a third party library.

I would also like to read the xml from the file and then display in a
page (links to documents, Text is the link text, Name is the file
name). Bound to a repeater, also displaying file size by querying the
file system.


Nov 12 '05 #2

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

Similar topics

5
7235
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler error) Save your work and restart Visual Studio .NET." has anyone seen this bug and can you confirm one way or the other whether or not it can corrupt your source files? (by 'corrupt' i mean: do anything to it that will cause it to fail to load and...
3
2306
by: SK | last post by:
I have a file. i get the creation time using File.GetCreationTime. then i go and delete that file. and then create it again and print the File.GetCreationTime. It is giving me the old creation time itself...y is it so..?
8
11362
by: Sam Collett | last post by:
Is there a basic guide on Xml document creation and editing (simpler than the MSDN docs). Say I want to create a file containing the following: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Files> <File> <Text>Test</Text> <Name>Test.html</Name> </File>
8
12306
by: Eddie Suey | last post by:
I want to add a new line to the begining of a text file. I dont want to write over existing data. How do I do this? the file is about 7 mb.
9
2961
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected text in the file. We've been trying to use the RichTextBox control to load
5
8657
by: Cameron Laird | last post by:
Question: import subprocess, StringIO input = StringIO.StringIO("abcdefgh\nabc\n") # I don't know of a compact, evocative, and # cross-platform way to exhibit this behavior. # For now, depend on cat(1). p = subprocess.Popen(, stdout = subprocess.PIPE, stdin = response)
0
1609
by: Hurricane | last post by:
I have my SQL database with a table that I am trying to have a gridview dislay with inline editing. It seems as if the dataset does not generate the apropriate update query, and therefore consequently the gridview does not automatically allow editing. I then try to change which update query that is selected being the dataRow, DataSet,dataTable or other DataRow And none of them work
1
1444
by: krithikav | last post by:
I create an excel file based on certain input from the user in ASP on the server and then display to the user after creation. Now In case the user modifies and clicks "Save" button, the modifications has to be saved back to the same file on the server. Is it possible with ASP? If so, please help me with a snippet. Krithika
6
38530
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
9670
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
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
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
7538
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
6776
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.