Have you tried a replace of the specific tags like below?
public class replacetagcontent {
static String inputFile = "C:/temp/shop.xml";
static String outputFile = "C:/temp/shop_modified.xml";
public static void main(String[] args) throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(inputFile);
// locate the node(s)
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new MyNamespaceContext());
NodeList shp_nodes = (NodeList)xpath.evaluate("//ns:shop", doc, XPathConstants.NODESET);
NodeList pers_nodes = (NodeList)xpath.evaluate("//ns:person", doc, XPathConstants.NODESET);
// make the change
for (int i = 0; i < shp_nodes.getLength(); i++) {
String name_value = shp_nodes.item(i).getTextContent();
shp_nodes.item(i).setTextContent(name_value.replace(":",""));
String title_value = pers_nodes.item(i).getTextContent();
pers_nodes.item(i).setTextContent(title_value.replace(":",""));
}
// save the result
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
}
private static class MyNamespaceContext implements NamespaceContext {
public String getNamespaceURI(String prefix) {
if("ns".equals(prefix)) {
return "http://www.example.org/schema";
}
return null;
}
public String getPrefix(String namespaceURI) {
return null;
}
public Iterator getPrefixes(String namespaceURI) {
return null;
}
}
}