Small program to manipulate this XML? how??

R

Ron

I would like to write a small program to manipulate this XML:

http://www.keepitsimplekid.com/xml/Ad00304.xml

What I want the program to do.

it would look at all.xml documents in a directory for example
directory C:\XML\rename

A Rename button would be pressed on the form and the program would go
through all the XML documents, first rename the documents from
FILENAME.XML to FIRNAME.XML.BAK - I still want to keep the
FILENAME.XML document, because that is the one the manipulation will
take place on.

I then want to look at each .xml document and REPLACE the Untitled Ad
text on the fourth line with whatever is here:

- <Application_Info AI_TYPE="ETS_ADVERTISER">
<Ai_Item NAME="LEAF GUARD" />

So <Meta NAME="Untitled Ad" <--- that Untitled Ad text would now
become:

<Meta NAME="LEAF GUARD"

I then want to save the file. So the directory will now contain the
old file with Untitled Ad in it as the filename.xml.bak and then the
converted file as .xml

Also, there will be more than 1 xml doc in that directory, so this
needs to go through each one, rename and manipulate them.

how would I do this? I have no Idea how to even begin this.
 
G

Guest

how would I do this? I have no Idea how to even begin this.


You have a couple ways to loading up the document and finding the
particular field to change. In the System.XML namespace you can use an
XMLReader or the XMLDocument classes. XMLReader is forward only and allows
you to loop through the document. XMLDocument loads the entire document in
a DOM and you can navigate directly to the location with an XPATH query.

I personally like using XPATH - it's very powerful and allows you to
perform queries, etc on the document. However if the document is not suited
to be queried (i.e. each doc is slightly different), perhaps consider
looping through all the elements and parse out the attributes
appropriately.
 

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