having re-read this, it may be that you only want to update the text content, i.e. 'xyz' in your example? if that is the case, that is fairly straightforward. example in this case is derived from http://javaalmanac.com/
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class BasicDom {
public static void main(String[] args) {
Document doc = parseXmlFile("infilename.x
// Obtain a node
Element element = (Element)doc.getElementsBy
// set the textContent
element.setTextContent("my
// write to a file
// refer to http://java.sun.com/webser
}
// Parses an XML file and returns a DOM document.
// If validating is true, the contents is validated against the DTD
// specified in the file.
public static Document parseXmlFile(String filename, boolean validating) {
try {
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.new
factory.setValidating(vali
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder
return doc;
} catch (SAXException e) {
// A parsing error occurred; the xml input is not valid
} catch (ParserConfigurationExcept
} catch (IOException e) {
}
return null;
}
}
Main Topics
Browse All Topics





by: kawasPosted on 2007-09-05 at 21:32:06ID: 19837649
that isnt valid xml ... also, most parsers wont allow you to change the tag name. you could consider using xsl to transform a document into a what you need.
m/egs/java x.xml.tran sform/ Basi cXsl.html
the following has an example of how to get things done with xsl. http://www.exampledepot.co