The list of methods to do XML Node Replace are organized into topic(s).
String
replaceComma(Node node) replace Comma
if (node.getFirstChild().getTextContent() == null) {
return "";
String[] ss = node.getFirstChild().getTextContent().split(",");
if (ss.length == 1) {
return ss[0] + " " + ss[0];
return ss[0] + " " + ss[1];
...
void
replaceNode(Node masterNode, Node oldNode, Node newNode) Replaces all occurrences of
oldNode in
masterNode with
newNode.
for (int i = 0; i < masterNode.getChildNodes().getLength(); i++) {
Node n = masterNode.getChildNodes().item(i);
replaceNode(n, oldNode, newNode);
if (n.getNodeType() == Node.TEXT_NODE && oldNode.getNodeType() == Node.TEXT_NODE
&& n.getNodeValue().equals(oldNode.getNodeValue())) {
masterNode.insertBefore(newNode.cloneNode(true), n);
masterNode.removeChild(n);
} else if (n.getNodeType() != Node.TEXT_NODE && n.getNodeName().equals(oldNode.getNodeName())
...
void
replaceText(Node node, String text) replace Text
for (;;) {
Node n = node.getFirstChild();
if (n == null)
break;
node.removeChild(n);
Text t = node.getOwnerDocument().createTextNode(text);
node.appendChild(t);
...
void
replaceVariable(final Node node, final String sVar, final String sValue) replace Variable
if (node.getNodeType() == Node.ELEMENT_NODE) {
final Element element = (Element) node;
final NamedNodeMap atts = element.getAttributes();
for (int i = 0; i < atts.getLength(); i++) {
final Attr attr = (Attr) atts.item(i);
if (attr.getValue().contains("$(" + sVar + ")")) {
String sAtt = attr.getValue();
sAtt = sAtt.replaceAll("\\$\\(" + sVar + "\\)", sValue);
...
void
replaceVariable(final Node node, final String var, final String valueString) replace Variable
switch (node.getNodeType()) {
case Node.ELEMENT_NODE: {
final Element element = (Element) node;
final NamedNodeMap atts = element.getAttributes();
for (int i = 0; i < atts.getLength(); i++) {
final Attr attr = (Attr) atts.item(i);
if (attr.getValue().contains("$(" + var + ")")) {
String att = attr.getValue();
...
void
replaceWith(Node oldNode, Node newNode) Replaces the old node with the new node
Node parentNode = oldNode.getParentNode();
if (parentNode != null) {
parentNode.replaceChild(newNode, oldNode);