Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
    
use code markup for those tags of yours –  Svish Aug 5 '10 at 14:22
add comment

3 Answers

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
share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
A nice tutorial. –  muntoo Feb 27 '11 at 9:15
    
Press Ctrl+R in Notepad++, and you can use regexes. –  muntoo Feb 27 '11 at 9:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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