XSLT solution:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pNewIpAddress" select="'192.68.0.1'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ipAddress/text()">
<xsl:value-of select="$pNewIpAddress"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on any document, all nodes of the document are copied "as-is" except for the text-node child of any ipAddress
element (regardless where this element is in the document). The latter is replaced with the value of an externally provided parameter, named $pNewIpAddress
.
For example, if the transformation is applied against this XML document:
<t>
<a>
<b>
<ipAddress>127.0.0.1</ipAddress>
</b>
<c/>
</a>
<d/>
</t>
the wanted, correct result is produced:
<t>
<a>
<b>
<ipAddress>192.68.0.1</ipAddress>
</b>
<c/>
</a>
<d/>
</t>
There are many Java-based XSLT processors and the proper place to understand how they can be invoked from Java is their documentation. One of the best such XSLT processors is Saxon and its documentation can be found at:
http://www.saxonica.com/documentation/documentation.xml