thanks for any help.
XML Example:
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Mar 2, 2008, 7:54 AM EST
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();
}
}
Jay3 reputationPosted Mar 18, 2008, 9:17 PM EDT