Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 36801 invoked from network); 19 Sep 2007 16:16:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Sep 2007 16:16:29 -0000 Received: (qmail 30783 invoked by uid 500); 19 Sep 2007 16:16:17 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 30735 invoked by uid 500); 19 Sep 2007 16:16:17 -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 30726 invoked by uid 99); 19 Sep 2007 16:16:17 -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 09:16:17 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [140.99.12.3] (HELO telesoft.com) (140.99.12.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2007 16:18:12 +0000 Received: from telesoft.com (localhost.localdomain [127.0.0.1]) by telesoft.com (8.12.11.20060308/8.12.11) with ESMTP id l8JGFpwq000738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 19 Sep 2007 09:15:52 -0700 Received: from localhost (james007@localhost) by telesoft.com (8.12.11.20060308/8.12.11/Submit) with ESMTP id l8JGFpiB000732 for ; Wed, 19 Sep 2007 09:15:51 -0700 Date: Wed, 19 Sep 2007 09:15:51 -0700 (MST) From: "Bond - James D." To: Jakarta Commons Users List Subject: Re: [ configuration ] setting top-level attributes In-Reply-To: <46F02DA2.2050101@oliver-heger.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: ClamAV version 0.90.2, clamav-milter version 0.90.2 on mail.telesoft.com X-Virus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org > 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
-- James Dalrymple --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org