Find and replace a text in XML file

March 2, 2010 at 01:32:27
Specs: Windows XP
I have an xml file that has the following text

<variables>
<variable name = “Service Account” value=”us\reetu” />
< variable name = “url” value=”dev.com” />
< variable name = “Release version” value=” ” />
< variable name = “SQL Account” value=”us\reetu” />
</variables>

The requirement is that the value for the release number will be provided by the user. So I have to get the user input and update the value in the XML file.
If user input is "9.5 Iteration 6", after the update, the file should look like this

<variables>
<variable name = “Service Account” value=”us\reetu” />
< variable name = “url” value=”dev.com” />
< variable name = “Release version” value=”9.5 Iteration 6” />
< variable name = “SQL Account” value=”us\reetu” />
</variables>

Please help me to write a script (batch file) to do the above task


See More: Find and replace a text in XML file

Report •


#1
March 2, 2010 at 12:22:43
in order to avoid a lot of the pitfalls of trying to use batch to process xml file (i did it a couple times, but it was not fun), i would try to use edlin. Edlin can work on files up to about 58K without having to buffer.
@echo off
set /p xx=enter value
>edl.in echo 1,#sRelease version" value ="
>> edl.in echo .
>> edl.in echo ^<variable name = “Release version” value=”%xx%” /^>
>> edl.in echo e
edlin xml.file<edl.in
more xml.file
::--------------- end of script
note that "Release version" IS case sensitive, so make sure it's the correct case.

Report •

#2
March 3, 2010 at 03:44:19
"in order to avoid a lot of the pitfalls of trying to use batch to process xml "

Hi nbrane,

Yeah, I spent over half an hour and got nowhere.

Any *ml probably needs VBS, but I can't help there.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
March 3, 2010 at 04:30:59
Sometimes it's possible to get away with batch on *ml, but let's face it, batch simply isn't the best text parsing language.

In fact *any* language that can string execute variables implicitly is less than ideal for most forms of text parsing.

Let's no forget that *ml are not regular languages, the only real way to parse them is to ignore all linebreaks and attempt to parse out values, bearing in mind self closing tags(i.e. <blah blah/>), escape codes(i.e &gt;) and input that fails to conform to convention(i.e. not closing the innermost tags first).

Nothing short of some sort of xml parser(either self written or third party) that takes into account all of the issues surrounding *ml can have a high probability of success.


Report •
Related Solutions


Ask Question