On 7/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> It would be nice if there were a way for the xmlproperty task to create pro=
> ps with an XPath like syntax.  Something like:
>
> temp.properties.entry(key=3D"appName")  would return Name

I think that we would want something like this, the other suggestions
imply some 'known' ordering on the properties in the xml file which
isn't in the spirit of things.

But the thing that surprises me is that the XML file is in the 'blessed
by Sun' format for properties, so ideally the property task should be
able to read it.  loadFromXML was introduced in 1.5, is the issue
related to not wanting to have to rewrite it for ant to work with older
java versions?

This should be done in the <property> task - as it is a sun specification
for an alternative property file format.
We should probally use loadFromXML, and not (initially) write
our own version.

In the meantime one can write a custom task, or use <script> or <scriptdef>
for example:
    <scriptdef name="load-xml-properties" language="beanshell">
         <attribute name="file"/>
         <attribute name="prefix"/>
        import java.io.*;
        import java.util.*;
        prefix = attributes.get("prefix") + ".";
        is = new FileInputStream(attributes.get("file"));
        Properties props = new Properties();
        props.loadFromXML(is);
        for (e = props.propertyNames(); e.hasMoreElements();) {
            key = e.nextElement();
            project.setNewProperty(prefix + key, props.getProperty(key));
        }
        is.close();
     </scriptdef>
     <load-xml-properties file="${basedir}/p.xml" prefix="temp"/>
     <echo>appname ${temp.appName}</echo>

Peter

Nik

> > ----- Original Message -----
> > From: [EMAIL PROTECTED]
> > To: user@ant.apache.org
> > Subject: Using Java xml properties file with Ant
> > Date: Fri, 20 Jul 2007 16:05:19 +0200 (CEST)
> >=20
> >=20
> > We are building a piece of software which has a number of Java
> > properties files in xml format (the kind which are read with
> > Properties.loadFromXML).  An example:
> >=20
> > <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd";>
> >=20
> > <properties>
> >    <entry key=3D"appName">Name</entry>
> >    <entry key=3D"startBean">Something</entry>
> >    <entry key=3D"versionNumber">2.5</entry>
> > </properties>
> >=20
> > I would like to be able to read these files and use their properties from
> > within ant.  The property task doesn't seem to handle properties files
> > in xml so I have been trying to use the xmlproperty task:
> >=20
> > <xmlproperty file=3D"temp.properties.xml" prefix=3D"temp" />
> >=20
> > But then all the values get thrown into the temp.properties.entry
> > property:
> >=20
> > <echo> using Prop=3D${temp.properties.entry} </echo>
> >=20
> > gives:
> >=20
> >       [echo]  using Prop=3DName,Something,2.5
> >=20
> > I assume that this should be trivial but I can't find a good solution to
> > get it to do the obvious thing (load three separate properties).
> > Suggestions?
> >=20
> > Second question, since the Sun dtd specifies SYSTEM (not a publicid), is
> > it possible to use xmlcatalog?
> >=20
> > Thanks,
> >=20
> > Nik
> > ____________________________________________________
> >=20
> > Conversation, n.:
> >     A vocal competition in which the one who is catching his breath
> >     is called the listener.
> >=20
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


____________________________________________________

"I am ready to meet my Maker.  Whether my Maker is prepared for the
great ordeal of meeting me is another matter."
                -- Winston Churchill

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to