I've got some C# code that sort of does what I want:
Looking at the xml files in area:
http://www.keepitsimplekid.com/xml
I want to change Untitled Ad at the top of the xml to the name of the
etn advertiser name in this xml for example LEAF GUARD OF LAKE ERIE
or REGIONAL CANCER CENTER, whatever is in that ETS Advertiser I want
to move to Untitled Ad, right now as you can see by the code I hard
code LEAF GUARD OF LAKE ERIE into the code, how can I do it
dynamically? thanks for any help..
code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e)
{
// Get a directory
String[] myFiles = System.IO.Directory.GetFiles("C:/
WAMP/", "*.xml", System.IO.SearchOption.TopDirectoryOnly);
// Show how many files were found
tb_Log.Text = myFiles.Length.ToString() + " files
acquired.";
if (MessageBox.Show("Would you like to continue?",
"Continue?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Show all files that match
foreach (string fileName in myFiles)
{
// Create our streamreader
StreamReader myStream = new
StreamReader(fileName);
// Loads file contents into string
string myDocument = myStream.ReadToEnd();
// Replaces Untitled Ad with new text
myDocument = myDocument.Replace("Untitled Ad",
"LEAF GUARD OF LAKE ERIE");
// Releases the file so we can overwrite it
myStream.Close();
// Creates a new streamwriter for the file
StreamWriter myNewStream = new
StreamWriter(fileName, false);
// Writes new text (with replacements) to stream
myNewStream.Write(myDocument);
// Saves changes to file and closes
myNewStream.Close();
}
// Print our completion
tb_Log.Text += Environment.NewLine;
tb_Log.Text += "...conversion completed";
}
else
{
tb_Log.Text += Environment.NewLine;
tb_Log.Text += "...process aborted";
}
}
}
}