Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Java and XML

Reply
Thread Tools

Java and XML

 
 
Lucia
Guest
Posts: n/a
 
      10-22-2003
Hello,

I'd like store all constants in my java-Application in an XML-file.
e.g.
<constant>
<name>con</name>
<type>long</type>
<value>10</value>
</constant>

After starting the application, the java class should be able to
create a variable with the name, the type and the value.

In this example, the java class should call the line at runtime:
long con = 10;

Has anyone an idea?

Thanks

Lucia
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      10-22-2003
Lucia wrote:
> Hello,
>
> I'd like store all constants in my java-Application in an XML-file.
> e.g.
> <constant>
> <name>con</name>
> <type>long</type>
> <value>10</value>
> </constant>
>
> After starting the application, the java class should be able to
> create a variable with the name, the type and the value.
>
> In this example, the java class should call the line at runtime:
> long con = 10;
>
> Has anyone an idea?


Does the XMLEncoder/XMLDecoder in the java.beans package help you?

f'up2 cjlp
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)

 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-22-2003
Lucia wrote:
> I'd like store all constants in my java-Application in an XML-file.
> e.g.
> <constant>
> <name>con</name>
> <type>long</type>
> <value>10</value>
> </constant>
>
> After starting the application, the java class should be able to
> create a variable with the name, the type and the value.
>
> In this example, the java class should call the line at runtime:
> long con = 10;
>
> Has anyone an idea?


In full generality: impossible. You could set the values via the reflection
API, but you'd still have the names and types fixed in the java classes.
You could generate the classes via a custom class loader, but then you
couldn't refer to the variables except via reflection, which would be
a really dumb and unnecessarily complex way to access config data.

All in all, it's simply a very bad idea: lots and lots of complexity
for practically no gain. Why not use a .properties file?

 
Reply With Quote
 
Steve Slatcher
Guest
Posts: n/a
 
      10-22-2003
Lucia wrote:
> Hello,
>
> I'd like store all constants in my java-Application in an XML-file.
> e.g.
> <constant>
> <name>con</name>
> <type>long</type>
> <value>10</value>
> </constant>
>
> After starting the application, the java class should be able to
> create a variable with the name, the type and the value.
>
> In this example, the java class should call the line at runtime:
> long con = 10;
>
> Has anyone an idea?


It wouldn't work exactly as you describe, but you could achieve a similar
effect with JAXB. Using JAXB you can easily convert an XML file into a
configuration object, and then you could get your "constants" from that
object.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ElementTree.XML(string XML) and ElementTree.fromstring(string XML)not working Kee Nethery Python 12 06-27-2009 06:06 AM
[Announce] Stylus Studio 2007 XML Enterprise Suite Released: XML Pipeline, XML Publishing and Data Conversion API's stylusstudio@gmail.com Java 0 09-26-2006 05:04 PM
[ANN] Stylus Studio 2007 XML Enterprise Suite Released: XML Pipeline, XML Publishing and Data Conversion API's Stylus Studio XML 0 09-26-2006 04:49 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM



Advertisments