1

I am using Notepad++ and attempting to replace all numeric strings within a specific tag (xxxxof my XML document with a new string which has been modified by a specific variable. Here's an example:

<start>501234</start>

round(501234 * 0.9) = 451111

<start>451111</start>

Is there a way to automatically find all numeric values within the start tag and do replace it by that same value multiplied by 0.9? I don't have to use Notepad++ if there's another tool that can do this.

Thanks!

1
  • use code markup for those tags of yours – Svish Aug 5 '10 at 14:22
1

use xslt to modify a input.xml:

<bla>
     <start>501234</start>
     <end>12345</end>
</bla>

and you want to multiply the number between the start tags with 0.9, then create a "transformation file" (transform.xsl):

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>

<!-- copy everything else -->
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<!-- transform what we are interested in -->
<xsl:template match="start">
    <foo><xsl:value-of select="number(.) * 0.9" /></foo>
</xsl:template>
</xsl:stylesheet>

and apply it like this:

% xsltproc transform.xsl input.xml
0

If You have minor knowledge of programing You can write your own very easily. You can use an XPathNavigator object to parse the XML with combination of C# or VB for task like that you should not spend more of half hour.

Begin Your own project with some of free versions of Visual Sudio and came to Stackoverflow.com whit your problems.

0

A very simple solution to this is to write a script (perhaps perl) to do a find and replace on your variable. this string matches everything between two tag variables ]>(.?). In perl you can just multiple the result of this regex with .9 and rewrite the answer. I deal with updating large xml files often and perl is by far the easiest solution to any of my problems

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.