thanks for any help.
XML Example:
Virtual. Every session is recorded and published here on CSharp TV.
Answer a question in the forums and earn +2 points for every reply.
Ask a questionKnow the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
JayPosted Mar 19, 2008, 1:17 AM
AlanPosted Mar 2, 2008, 12:54 PM
The following example shows how you can read data from an existing XML file and then write out updated data to another file (or overwrite the first one if you're brave). Sorry, it's in C# as I haven't had time to translate it into VB.Net but I'm sure you'll be able to follow it OK:
using System;
using System.Xml;
class Test
{
static void Main()
{
using (XmlTextReader reader = new XmlTextReader("jay.xml"))
{
reader.ReadToFollowing("Style");
string name = reader.GetAttribute("name");
Console.WriteLine(name);
reader.ReadToFollowing("File");
string backFile = reader.ReadElementString("File");
Console.WriteLine(backFile);
string stretched = reader.ReadElementString("Stretched");
Console.WriteLine(stretched);
string cropped = reader.ReadElementString("Cropped");
Console.WriteLine(cropped);
reader.ReadToFollowing("File");
string foreFile = reader.ReadElementString("File");
Console.WriteLine(foreFile);
string transparency = reader.ReadElementString("Transparency");
Console.WriteLine(transparency);
string enabled = reader.ReadElementString("Enabled");
Console.WriteLine(enabled);
}
using (XmlTextWriter writer = new XmlTextWriter("jay2.xml", null))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("ExampleMain");
writer.WriteStartElement("Settings");
writer.WriteStartElement("Style");
writer.WriteStartAttribute("name");
writer.WriteString("test124");
writer.WriteEndAttribute();
writer.WriteStartElement("Background");
writer.WriteStartElement("File");
writer.WriteString("image03.bmp");
writer.WriteEndElement();
writer.WriteStartElement("Stretched");
writer.WriteString("1");
writer.WriteEndElement();
writer.WriteStartElement("Cropped");
writer.WriteString("0");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("Foreground");
writer.WriteStartElement("File");
writer.WriteString("image6.bmp");
writer.WriteEndElement();
writer.WriteStartElement("Transparency");
writer.WriteString("32");
writer.WriteEndElement();
writer.WriteStartElement("Enabled");
writer.WriteString("0");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
Console.ReadLine();
}
}