Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 14845 invoked from network); 19 Sep 2007 20:44:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Sep 2007 20:44:36 -0000 Received: (qmail 45424 invoked by uid 500); 19 Sep 2007 20:44:23 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 45243 invoked by uid 500); 19 Sep 2007 20:44:23 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 45234 invoked by uid 99); 19 Sep 2007 20:44:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2007 13:44:23 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_HELO_PASS,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [212.227.126.179] (HELO moutng.kundenserver.de) (212.227.126.179) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2007 20:46:18 +0000 Received: from p5B09B656.dip0.t-ipconnect.de [91.9.182.86] (helo=[192.168.178.20]) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis), id 0MKxQS-1IY6Ot0HiH-0008NF; Wed, 19 Sep 2007 22:43:59 +0200 Message-ID: <46F18A25.3030308@oliver-heger.de> Date: Wed, 19 Sep 2007 22:44:21 +0200 From: Oliver Heger User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: [ configuration ] setting top-level attributes References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX19agp5yrl7mK50gNIeE2S5DT1vJhxlAYwmUP5w ClCiLRZU8DNSm1DK3v+YrXbnxi/T1aG+zggotU7b28HlKpm2BV +gDgcfJyCNTX0T8WsbVqg== X-Virus-Checked: Checked by ClamAV on apache.org Bond - James D. wrote: >> Bond - James D. wrote: >>> Hopefully this is a simple one. I have a semi-non-standard xml file that >>> has attributes in the Top-level element and I'm not able to set the >>> attributes on it. How would I do that with XMLConfiguration? I tried the >>> following but it didn't work: >>> >>> xmlCfg.setProperty("[@payloadID]", ""+System.currentTimeMillis()); >> Hm, your code should work. I added the following unit test, which runs >> successful: >> >> /** >> * Tests setting an attribute on the root element. >> */ >> public void testSetRootAttribute() throws ConfigurationException >> { >> conf.setProperty("[@test]", "true"); >> assertEquals("Root attribute not set", "true", conf >> .getString("[@test]")); >> conf.save(testSaveConf); >> XMLConfiguration checkConf = new XMLConfiguration(); >> checkConf.setFile(testSaveConf); >> assertTrue("Attribute not found after save", checkConf >> .containsKey("[@test]")); >> } >> >> (where conf is a XMLConfiguration). As you can see, I also only specify >> the attribute part of the key. >> >> Can you double-check with this code? Or can you provide an example code >> fragment, which does not work? >> >> Oliver > > Ok, I can't get it to work ... here's my code: > > String xmlTemplate = "c:\\temp\\ordermessage.xml"; > String newXmlTemplate = "c:\\temp\\changedordermessage.xml"; > > XMLConfiguration xmlCfg = new XMLConfiguration(xmlTemplate); > xmlCfg.setValidating(false); > xmlCfg.setEncoding("UTF-8"); > xmlCfg.setProperty("[@payloadID]", ""+System.currentTimeMillis()); > xmlCfg.setProperty("[@timestamp]", new Date().toString()); > FileWriter outter = new FileWriter(newXmlTemplate); > xmlCfg.save(outter); > outter.close(); > xmlCfg.clear(); > > And here is the XML file: > > > > >
> > > 12345 > > >
>
> > After some further testing: you are right, there seems to be a bug! If the attribute already exists, a new value is not written. Can you open a ticket in jira [1], please? Thanks. Oliver [1] http://commons.apache.org/configuration/issue-tracking.html --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org