471,873 Members | 1,010 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help required to update information in an XML

Hello dear VB experts.
I am very new to VB scripting.
I wanted to know if this is possible.

This is the requirement.
I have an XML file. I need an application that updates the information represented by the XML tags ( say "Name" and "Description" in the example below.)
Consider the XML file to have following structure.

<Start>
<Item>
<Name> ABC </Name>
<Description> I need to change this.</Description>
</Item>
<Item>
<Name> XYZ </Name>
<Description> I need to change also this. </Description>
</Item>
<Item>
<Name> PQR </Name>
<Description>I need to change Name and Description here
</Description>
</Item>
</Start>

I need the application to change the segments given in bold.
Solutions to this or suggestions are welcome.
Thanks in advance.

Regards,
Shyam
Feb 22 '07 #1
2 922
Killer42
8,435 Expert 8TB
I believe there are a lot of tools available to work with XML. However, if you insist on doing it yourself, you should be able to get away with reading the file as plain text, line by line, and using Instr() function to find the tags and Mid() to pull out the text. Then change or replace the string, and concatenate the line back together.

It depends a bit on how consistent the layout is. For instance, if you know that it will always be formatted with each entry on a single line like your sample, then you could just do something really simple like...
Expand|Select|Wrap|Line Numbers
  1. If Left(strText, 6) = "<Name>" Then
  2.   strName = Mid(strText, 7, Len(strText) - 13)
  3.   ' Make your change to strName, then...
  4.   strText = "<Name>" & strName & "</Name>"
  5. End If
Of course, for a real application I would try to write this as a more generally applicable algorithm rather than hard-coding things like strings and lengths.
Feb 23 '07 #2
vijaydiwakar
579 512MB
Hello dear VB experts.
I am very new to VB scripting.
I wanted to know if this is possible.

This is the requirement.
I have an XML file. I need an application that updates the information represented by the XML tags ( say "Name" and "Description" in the example below.)
Consider the XML file to have following structure.

<Start>
<Item>
<Name> ABC </Name>
<Description> I need to change this.</Description>
</Item>
<Item>
<Name> XYZ </Name>
<Description> I need to change also this. </Description>
</Item>
<Item>
<Name> PQR </Name>
<Description>I need to change Name and Description here
</Description>
</Item>
</Start>

I need the application to change the segments given in bold.
Solutions to this or suggestions are welcome.
Thanks in advance.

Regards,
Shyam
Dear Shyam
XML files are not that much supported in VB
if possible try to use vb.net
Its very easy in .net
Feb 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Dom Boyce | last post: by
2 posts views Thread by MyNameIsnt | last post: by
1 post views Thread by Alpha | last post: by
3 posts views Thread by Adriano | last post: by
2 posts views Thread by cryon.b | last post: by
23 posts views Thread by casper christensen | last post: by
2 posts views Thread by sorobor | last post: by
reply views Thread by YellowAndGreen | last post: by

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.