Want to build a small program to change text in xml file, how??

R

Ron

I need to write a little vb.net app that looks at XML files and
manipulates text in them. Here is what I need to do and I have NO idea
how to do something like this.

here is an example file: also can be found at: http://www.keepitsimplekid.com/xml/Ad00304.xml

<XMD-entity ENTITY_TYPE="Ad" PAGE_NO="3" ID="Ad00304" BOX="450 1030
1229 1429" LANGUAGE="English" SNP="Ad00304S.jpg" SNP_WIDTH="156"
SNP_HEIGHT="80">
<Meta NAME="Untitled Ad" DESCRIPTION="" SUBTYPE="" BASE_HREF="ETN/
2007/05/02" SOURCE_TYPE="PDF" PUBLICATION="ETN" SECTION="Up Close"
ISSUE_DATE="02/05/2007" WORDCNT="140" RELEASE_NO="05-02_Complete"
PAGE_ID="section1page3" PAGE_TYPE="Single" PAGE_WIDTH="515"
PAGE_HEIGHT="919" DEFAULT_IMG_EXT="png"
PDF_DESTINATION_MAPPED="OLV0_Entity_0003_0001" IMAGES_RESOLUTION="100"
XMD_VER="2.6.209" PAGE_LABEL="3A"/>
<Link SOURCE="05-02_Complete.pdf" FIRST_ID="Ar00300" LAST_ID="Pc00306"
NEXT_ID="Ad00305" PREV_ID="Ad00303" TOC_ID="C:/Olive/Repository/ETN/
2007/05/02/TOC.xml"/>
−
<Application_Data AD_NUMBER="1" PUB_DATE="1" ETS_ADVERTISER="1"
CATEGORY="1" AD_WIDTH="1" AD_HEIGHT="1" PAGE_NUMBER="1"
SECTION_NAME="1" SECTION_PAGE_NUMBER="1" PDF_NAME="1" AD_X="1"
AD_Y="1" WEBSITE="1" EMAIL="1" UPSOLD="1">
−
<Application_Info AI_TYPE="AD_NUMBER">
<Ai_Item NAME="1515578"/>
</Application_Info>
−
<Application_Info AI_TYPE="PUB_DATE">
<Ai_Item NAME="05/02/07"/>
</Application_Info>
−
<Application_Info AI_TYPE="ETS_ADVERTISER">
<Ai_Item NAME="LEAF GUARD OF LAKE ERIE"/>
</Application_Info>

I have Bolded what I am working with. At the top of the xml where it
says Untitled Ad I want to replace that text with whatever is in the
NAME of the ETS Advertiser, in this case LEAF GUARD OF ERIE

And I want to make the change and save the changes. I then want to be
able to loop through all .xml files in the directory and do this text
swap. Not all xml files will have the same advertiser name, they all
have different ones.

How would I build a program to do this?
 
C

Charlie Brown

I need to write a little vb.net app that looks at XML files and
manipulates text in them. Here is what I need to do and I have NO idea
how to do something like this.

here is an example file: also can be found at:http://www.keepitsimplekid.com/xml/Ad00304.xml

<XMD-entity ENTITY_TYPE="Ad" PAGE_NO="3" ID="Ad00304" BOX="450 1030
1229 1429" LANGUAGE="English" SNP="Ad00304S.jpg" SNP_WIDTH="156"
SNP_HEIGHT="80">
<Meta NAME="Untitled Ad" DESCRIPTION="" SUBTYPE="" BASE_HREF="ETN/
2007/05/02" SOURCE_TYPE="PDF" PUBLICATION="ETN" SECTION="Up Close"
ISSUE_DATE="02/05/2007" WORDCNT="140" RELEASE_NO="05-02_Complete"
PAGE_ID="section1page3" PAGE_TYPE="Single" PAGE_WIDTH="515"
PAGE_HEIGHT="919" DEFAULT_IMG_EXT="png"
PDF_DESTINATION_MAPPED="OLV0_Entity_0003_0001" IMAGES_RESOLUTION="100"
XMD_VER="2.6.209" PAGE_LABEL="3A"/>
<Link SOURCE="05-02_Complete.pdf" FIRST_ID="Ar00300" LAST_ID="Pc00306"
NEXT_ID="Ad00305" PREV_ID="Ad00303" TOC_ID="C:/Olive/Repository/ETN/
2007/05/02/TOC.xml"/>
−
<Application_Data AD_NUMBER="1" PUB_DATE="1" ETS_ADVERTISER="1"
CATEGORY="1" AD_WIDTH="1" AD_HEIGHT="1" PAGE_NUMBER="1"
SECTION_NAME="1" SECTION_PAGE_NUMBER="1" PDF_NAME="1" AD_X="1"
AD_Y="1" WEBSITE="1" EMAIL="1" UPSOLD="1">
−
<Application_Info AI_TYPE="AD_NUMBER">
<Ai_Item NAME="1515578"/>
</Application_Info>
−
<Application_Info AI_TYPE="PUB_DATE">
<Ai_Item NAME="05/02/07"/>
</Application_Info>
−
<Application_Info AI_TYPE="ETS_ADVERTISER">
<Ai_Item NAME="LEAF GUARD OF LAKE ERIE"/>
</Application_Info>

I have Bolded what I am working with. At the top of the xml where it
says Untitled Ad I want to replace that text with whatever is in the
NAME of the ETS Advertiser, in this case LEAF GUARD OF ERIE

And I want to make the change and save the changes. I then want to be
able to loop through all .xml files in the directory and do this text
swap.  Not all xml files will have the same advertiser name, they all
have different ones.

How would I build a program to do this?

If the XML is properly formatted you can use the ablities of the
System.XML namespace. You could load everything into a XMLDocument
and iterate through the nodes using XPATH queries. Once you've
established that with one file, it would be simple to write a loop
that opens a directory, loads each file as an XMLDocument and iterates
through the nodes making the proper changes.

http://support.microsoft.com/default.aspx/kb/318499

http://samples.gotdotnet.com/quickstart/howto/doc/Xml/QueryXmlDocumentXPath..aspx

That should get you started, just reply with more questions as they
come up and someone can help lead you in the right direction.
 

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