473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I fix this code??

Ron
I have this 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);
}
}

and I am working with the .xml files in this directory:
http://www.keepitsimplekid.com/xml

I want the text Untitled Ad in these xml docs to be replaced with the
Name of the ETS Advertiserr, in these examples LEAF GUARD OF LAKE ERIE
and REGIONAL CANCER CENTER

Now this code takes new value and inserts that text in the ETS
Advertiser name and also replaces Untitled Ad with new value.

How can I modify this code to read whatever is in ETS ADVERTISER and
then replace Untitled Ad with the text it gets from there.?

May 16 '07 #1
3 1370
On May 16, 4:53 am, Ron <pts4...@yahoo.comwrote:
Now this code takes new value and inserts that text in the ETS
Advertiser name and also replaces Untitled Ad with new value.

How can I modify this code to read whatever is in ETS ADVERTISER and
then replace Untitled Ad with the text it gets from there.?
I guess that what you have a problem with is not reading finding files
but manipulating XML document. You are quite close with your solution
but I find it quite hard to read. Here is a solution to your problem
written in a slighly more readable fashion:

const string DocumentPath = @"C:\Ad00304.xml";
const string DocumentCopyPath = @"C:\Ad00304_Copy.xml";
const string EtsAdvertiserXPath = "/XMD-entity/Application_Data/
Application_Info[@AI_TYPE='ETS_ADVERTISER']/Ai_Item";
const string MetaXPath = "/XMD-entity/Meta";

XmlDocument doc = new XmlDocument();
doc.Load(DocumentPath);

XmlNode etsAdvertiserItemNode =
doc.SelectSingleNode(EtsAdvertiserXPath);
string etsAdvertieserName =
etsAdvertiserItemNode.Attributes["NAME"].InnerText;

XmlNode metaNode = doc.SelectSingleNode(MetaXPath);
metaNode.Attributes["NAME"].InnerText = etsAdvertieserName;

doc.Save(DocumentCopyPath);

--
Marcin Hoppe
http://devlicio.us/blogs/marcin_hoppe/

May 16 '07 #2
Ron
When I run this I get a bunch of errors. Is there a way though for me
to look at all .xml files in the directory c:\convert?

would I just do:
const string DocumentPath = @"C:\convert\*.xml";
const string DocumentCopyPath = @"C:\convert\*_Copy.xml";

? Would this work?

On May 16, 3:03 am, Marcin Hoppe <marcin.ho...@gmail.comwrote:
On May 16, 4:53 am, Ron <pts4...@yahoo.comwrote:
Now this code takes new value and inserts that text in the ETS
Advertiser name and also replaces Untitled Ad with new value.
How can I modify this code to read whatever is in ETS ADVERTISER and
then replace Untitled Ad with the text it gets from there.?

I guess that what you have a problem with is not reading finding files
but manipulating XML document. You are quite close with your solution
but I find it quite hard to read. Here is a solution to your problem
written in a slighly more readable fashion:

const string DocumentPath = @"C:\Ad00304.xml";
const string DocumentCopyPath = @"C:\Ad00304_Copy.xml";
const string EtsAdvertiserXPath = "/XMD-entity/Application_Data/
Application_Info[@AI_TYPE='ETS_ADVERTISER']/Ai_Item";
const string MetaXPath = "/XMD-entity/Meta";

XmlDocument doc = new XmlDocument();
doc.Load(DocumentPath);

XmlNode etsAdvertiserItemNode =
doc.SelectSingleNode(EtsAdvertiserXPath);
string etsAdvertieserName =
etsAdvertiserItemNode.Attributes["NAME"].InnerText;

XmlNode metaNode = doc.SelectSingleNode(MetaXPath);
metaNode.Attributes["NAME"].InnerText = etsAdvertieserName;

doc.Save(DocumentCopyPath);

--
Marcin Hoppehttp://devlicio.us/blogs/marcin_hoppe/

May 16 '07 #3

"Ron" <pt*****@yahoo.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
When I run this I get a bunch of errors. Is there a way though for me
to look at all .xml files in the directory c:\convert?

would I just do:
const string DocumentPath = @"C:\convert\*.xml";
const string DocumentCopyPath = @"C:\convert\*_Copy.xml";
no, but see foreach and DirectoryInfo.GetFiles()
>
? Would this work?

On May 16, 3:03 am, Marcin Hoppe <marcin.ho...@gmail.comwrote:
>On May 16, 4:53 am, Ron <pts4...@yahoo.comwrote:
Now this code takes new value and inserts that text in the ETS
Advertiser name and also replaces Untitled Ad with new value.
How can I modify this code to read whatever is in ETS ADVERTISER and
then replace Untitled Ad with the text it gets from there.?

I guess that what you have a problem with is not reading finding files
but manipulating XML document. You are quite close with your solution
but I find it quite hard to read. Here is a solution to your problem
written in a slighly more readable fashion:

const string DocumentPath = @"C:\Ad00304.xml";
const string DocumentCopyPath = @"C:\Ad00304_Copy.xml";
const string EtsAdvertiserXPath = "/XMD-entity/Application_Data/
Application_Info[@AI_TYPE='ETS_ADVERTISER']/Ai_Item";
const string MetaXPath = "/XMD-entity/Meta";

XmlDocument doc = new XmlDocument();
doc.Load(DocumentPath);

XmlNode etsAdvertiserItemNode =
doc.SelectSingleNode(EtsAdvertiserXPath);
string etsAdvertieserName =
etsAdvertiserItemNode.Attributes["NAME"].InnerText;

XmlNode metaNode = doc.SelectSingleNode(MetaXPath);
metaNode.Attributes["NAME"].InnerText = etsAdvertieserName;

doc.Save(DocumentCopyPath);

--
Marcin Hoppehttp://devlicio.us/blogs/marcin_hoppe/


May 17 '07 #4

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.