Assuming your file is valid and well-formed XML, you are probably better off using an XSLT processor to modify it. Here is a stylesheet which does what you want.
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="Journals">
<Journals note="cleaned up" >
<xsl:apply-templates select="Journal" />
</Journals>
</xsl:template>
<xsl:template match="Journal">
<xsl:choose>
<xsl:when test="JournalAmount < 0.00">
<xsl:element name="Journal">
<JournalCode>1</JournalCode>
<JournalType><xsl:value-of select="JournalType"/></JournalType>
<JournalEntry><xsl:value-of select="JournalEntry"/></JournalEntry>
<JournalAmount><xsl:value-of select="JournalAmount * -1" /></JournalAmount>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The following example file contains 2 jounal entries, one positive and one negative
Code:
<?xml version = "1.0"?>
<Journals>
<Journal>
<JournalCode>3</JournalCode>
<JournalType>L</JournalType>
<JournalEntry>SG</JournalEntry>
<JournalAmount>5.56</JournalAmount>
</Journal>
<Journal>
<JournalCode>2</JournalCode>
<JournalType>L</JournalType>
<JournalEntry>SG</JournalEntry>
<JournalAmount>-0.05</JournalAmount>
</Journal>
</Journals>
Use xsltproc the post-transformation output for the above file is:
Code:
$ xsltproc convert.xsl infile.xml > outfile.xml
<?xml version="1.0"?>
<Journals note="cleaned up">
<Journal>
<JournalCode>3</JournalCode>
<JournalType>L</JournalType>
<JournalEntry>SG</JournalEntry>
<JournalAmount>5.56</JournalAmount>
</Journal>
<Journal>
<JournalCode>1</JournalCode>
<JournalType>L</JournalType>
<JournalEntry>SG</JournalEntry>
<JournalAmount>0.05</JournalAmount>
</Journal>
</Journals>