How to update a attribute value in java

Hi All,

I have a xml file which looks like

<languages>

<c>10</c>

<java>1.5</java>

<vb>7</vb>

</languages>

now i have to parse the xml and update the value of <java> tag to 1.6,can

anyone please provide the code snippet for above requirement.

Thanks,

Ants Balajei.

[390 byte] By [Antsa] at [2007-11-27 7:33:51]
# 1

> now i have to parse the xml and update the value of

> <java> tag to 1.6,can

> nyone please provide the code snippet for above

> requirement.

Here is the snippet

//Get the document using DOM parser

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();.

Document document = builder.parse(file); // ur xml file

XPath xpath = XPathFactory.newInstance().newXPath();

XPathExpression expression = xpath.compile("//java");

Node aNode = (Node) expression.evaluate(document, XPathConstants.NODE); //gets the desired node

// update the text

aNode.setTextContent("new text");

//save the document

haishaia at 2007-7-12 19:14:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...