Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading properties with xml

 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, how do you read properties from an xml file in Tocmat? I'm talking about props that I set (variables), not config info for server or webapps..

I just want to read props from an xml file like you would from a .properties or .config file.. I have looked and looked, found a xml-apis.jar in Tomcat (common/endorsed), but did not come w/docs... there is also a xercesImpl.jar, do I need this.. can I put properties I set in web.xml or do I need a different xml file..

I have searched google ad nauseum.. all results are about Tomcat configurations for servers, etc...

thank you very much..

-v
[ March 08, 2006: Message edited by: Bear Bibeault ]
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, placing the XML file with the "properties" definition in the class
path (preferabbly in the WEB-INF/classes directory if this is only for a
specific webapp, and then using getResourceAsStream(propsFileName) should
do it for you. Read the API doc for the Properties class and the routine
loadFromXML(InputStream)
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how is this used pls..

have an xml file called props.xml in web-inf/classes; in servlet:

Class.getResourceAsStream(props); // won't compile..

also tried

Class.getResourceAsStream(props.xml);// also doesn't compile..

what do I put at top of xml? just for testing purposes put this in xml:


<?xml version="1.0" encoding="ISO-8859-1"?>
<props>
<myName>Veronica</myName>
</props>

not sure header is right.. I just can't find info on this; all info I find related to xml/Tomcat deals with Tomcat/webapp configuration, not reading properties..

thank you very much..

-v
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.. this compiled:

InputStream is = getClass().getResourceAsStream("props.xml");

however, loadFromXML() method is 1.5-only.. how do you do this if you're on 1.4 or 1.3.. many thanks...

-v
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing Tomcat-specific, or even web-specific, about this question. Moved to the XML forumm with an appropriate title change.
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Veronica Damian:
however, loadFromXML() method is 1.5-only.. how do you do this if you're on 1.4 or 1.3.. many thanks...
You don't. The Properties class doesn't support the XML format in those versions.

That's not to say you can't use XML-formatted information in those versions. You just can't use the Properties class to read it in. You would have to write your own code to extract the information, or perhaps use somebody else's code (such as Apache Commons Digester).
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.. I'm on Tomcat 3, it comes with a xml-apis.jar, but no docs.. do you know where I can find docs for it.. thank you..

-v
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic