XML file rep does not change (was [jdom-interest] (no subject))

Wolfgang Werner wwerner at picturesafe.de
Wed Jun 7 10:23:34 PDT 2000


Hi,

what you are doing is
	* reading a xml file to memory
	* altering the in-memory content

to see the xml file change, you have to write your
modified document to disk (with the help of the
XML Outputter).

Thanks,

Wolfgang Werner

By the way: Please take the time to fill in a good
subject line! This helps in tracking questions and
answers.

> Von: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]Im Auftrag von nagarajan madhavan
> Gesendet: Mittwoch, 7. Juni 2000 18:41
> An: jdom-interest at jdom.org
> Betreff: [jdom-interest] (no subject)
>
>
> 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
>




More information about the jdom-interest mailing list