code almost working except... ? help ??

R

Ron

This code is almost doing what I want it to do, here is the code:
private void btnConvert_Click(object sender, EventArgs e)
{
// Get a directory
string path = @"c:\WAMP\";

foreach (string fileName in Directory.GetFiles(path,
"*.xml"))
{
XmlDocument xdoc = new XmlDocument();

xdoc.Load(fileName);

((XmlAttribute)xdoc.SelectSingleNode("/XMD-entity/Meta/
@name")).Value = "new value";

((XmlAttribute)xdoc.SelectSingleNode("/XMD-entity/
Application_Data/Application_Info[@AI_TYPE='ETS_ADVERTISER']/Ai_Item/
@name")).Value = "new value";

xdoc.Save(fileName);
}
}

What this code does is it reads all .xml files in a directory, XML
files like the 2 examples here: http://www.keepitsimplekid.com/xml
it then takes and Replaces Untitled Ad twoards the top of the xml doc
with the text New Value. It also replaces the ETS ADVERTISER name,
for example REGIONAL CANCER CENTER, or LEAF GUARD OF LAKE ERIE with
the text new value.

Here is what I want to do. I will delete the line of code that
replaces the ETS ADVERTISER name with New Value, I want to keep the
line of code near the top that replaces the words Untitled Ad.
Instead of replacing Untitled Ad with new value, I want to replace it
with the value that is ETS ADVERTISER name, so Untitled Ad would be
replaced with LEAF GUARD OF LAKE ERE, or, REGINAL CANCER CENTER

How do I replace / fix this line of code to do that?
((XmlAttribute)xdoc.SelectSingleNode("/XMD-entity/Meta/@name")).Value
= "new value";

so I don't want it to = the text new value, I want it to = whatever
the ETS ADVERTISER name actually is.
 
M

Morten Wennevik [C# MVP]

Hi Ron,

I'm not entirely sure I grasped your problem. It looks to me like you want to replace "new value" with the AI_ITEM Name value from the ETS_ADVERTISER node. If so, just rearrange the two lines:


string value = ((XmlAttribute)xdoc.SelectSingleNode("/XMD-entity/Application_Data/Application_Info[@AI_TYPE='ETS_ADVERTISER']/Ai_Item/@NAME")).Value;

((XmlAttribute)xdoc.SelectSingleNode("/XMD-entity/Meta/@NAME")).Value =value;


If this is not what you want, please feel free to correct me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top