<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="MSHTML 6.00.2800.1528" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV id=idOWAReplyText31164 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>In short...</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>// call the build method on a reader to
produce a Document object. If you have a File, and URL, a String (via a
StringReader), etc. use SAXBuilder.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>// If you have a DOM object already parsed,
use DOMBuilder.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>Document doc = new SAXBuilder().build(new
File("/path/to/your/file.xml"));</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>// find the specific Element you want to
modify. this step could also be done by XPath</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>for (Iterator it =
doc.getRootElement().getChildren("id").iterator; it.hasNext();) {</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> Element el = (Element)
it.next();</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> if
(element.getAttributeValue("art").equals("293")) {</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2> // do some
modification, like element.setAttribute("done", "true");</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>
break;</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> }</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>}</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>// serialize the Document object to a
String. You can output to a File, an OutputStream, a String etc. through
XMLOutputter.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>//To output to DOM, use DOMOutputter and to
output to a SAX ContentHandler, use </FONT><FONT face=Arial
size=2>SAXOutputter.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>String des = new
XMLOutputter().outputString(doc);</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org on behalf
of Roberto Marra<BR><B>Sent:</B> Wed 2/15/2006 10:31 AM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest] Modify an xml thru
JDOM<BR></FONT><BR></DIV>
<DIV>
<DIV><FONT face="Trebuchet MS">Hi guys Im new in this list & new with JDOM,
so "hi" to everybody & thanx for your precious comments &
helps.</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS">My question is:</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS">Let say that I got an XML file like this
one:</FONT></DIV>
<DIV><FONT face="Lucida Sans Unicode"></FONT> </DIV>
<DIV><FONT face="Lucida Sans Unicode"><FONT face=Courier size=1><?xml
version="1.0" encoding="ISO-8859-1"?><BR><righeOrdine
nrOrd="1"><BR> <id
art="292"><BR> <sequenza>1.1</sequenza><BR> <codice>110061</codice><BR> <descrizione>PET
FILM CORONA
OUTSIDE</descrizione><BR> <tipologia>PTR</tipologia><BR> <trattamento>CR2</trattamento><BR> </id><BR> <id
art="293"><BR> <sequenza>2.1</sequenza><BR> <codice>110071</codice><BR> <descrizione>PET
PVDC
COATED</descrizione><BR> <tipologia>PTR</tipologia><BR> <trattamento>PC1</trattamento><BR> </id><BR></righeOrdine></FONT></FONT></DIV>
<DIV><FONT face="Lucida Sans Unicode"><FONT face=Courier
size=1></FONT></FONT> </DIV>
<DIV><FONT face="Lucida Sans Unicode"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS">what I would like to do is thru JDOM update just
some value of the <id art="293">, let say I would update the "codice" from
110071 to 112071. Im sure is possible to do that, can you just suggest me some
tips&tricks to do it? (of course using java)</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS">Any help is appriciated</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS">Cheers</FONT></DIV>
<DIV><FONT face="Trebuchet MS">Roberto</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Trebuchet MS"><BR></FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><FONT face="Lucida Sans Unicode"></FONT> </DIV>
<DIV><FONT face="Lucida Sans Unicode"> </DIV></FONT></DIV></BODY></HTML>