[jdom-interest] (no subject)

nagarajan madhavan nagaragan at hotmail.com
Wed Jun 7 09:41:17 PDT 2000


Hello,

   see this code snippet;


org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
             Document doc = builder.build(new 
File("E:\\java_classes\\file2.xml"));
              			Element element=doc.getRootElement();
			Element kid= element.getChild("rating");
			kid.setContent("0");
			   String x  =kid.getContent();
		System.out.println("value of x-- rating is" +x+"\n\n");


"file2"  is an existing xml file;

it has an attribute, by name "rating"  ( <rating>400</rating> ).

In this code we are trying to set that to Zero ( i don't know if it will be 
considered as a  string or is there a way of maintaining the actual data 
type, if any ; because actually "rating" keeps integer values).


When we use,

   XMLOutputter fmt = new XMLOutputter();
      fmt.output(doc, System.out);


The output on the console gives the value of "rating" as 0.

But when u open the actual file , "file2.xml", the value of rating is not 
changed; the old 400 only;

The question is how to modify the value of a particular attribute( element) 
in an already existing  XML files ?

Thanks in advance

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com




More information about the jdom-interest mailing list