Filling Java Vector using XML Config file

H

homi

Hi All,

I am writing a Java code that uses a XML Config file to configure
itself. Sample of the XML file has shown below. I want to have a peace
of java code to reads that config file and import all the data to a
class structure that I have designed before. In this case I will have
a class name AppGroup and the whole config file will be stored in
array of AppGroup objects. What is the best was of doing such a thing.
I’ve already looked at Castor but seem to complicate to me.
Thanks in advance for your help.


<?xml version="1.0"?>

<FConfig>
<ExtraConf>
<Name>TEST</Name>
<Timeout>100</Timeout>
</ExtraConf>
<AppGroup>
<Other>
<AppName>BILL5</AppName>
<FileSequenceIn>aaabbb</FileSequenceIn>
<TransferAlarm>transAlarmCall</TransferAlarm>
</Other>
<TransConf>
<Direction>INPUT</Direction>
<SourceDir>/client/home/ttt</SourceDir>
<FilePattern>aaavvv</FilePattern>
<TargetDir>/home/rrr</TargetDir>
<StateFile>auditState</StateFile>
</TransConf>
<TransConf>
<Direction>OUTPUT</Direction>
<SourceDir>/client/home/ggg</SourceDir>
<FilePattern>aaaeee</FilePattern>
<TargetDir>/home/yyy</TargetDir>
<StateFile>auditState2</StateFile>
</TransConf>
</AppGroup>
<AppGroup>
………………………..
</AppGroup>



Thanks,

Homer
 
C

Chris Smith

homi said:
Hi All,

I am writing a Java code that uses a XML Config file to configure
itself. Sample of the XML file has shown below. I want to have a peace
of java code to reads that config file and import all the data to a
class structure that I have designed before. In this case I will have
a class name AppGroup and the whole config file will be stored in
array of AppGroup objects. What is the best was of doing such a thing.
I’ve already looked at Castor but seem to complicate to me.

A simple SAX parser could do it, if you have no need for updates and
such over time. Look into JAXP and the SAX API for details. You will
have to actually write some code to respond to elements of the config
file by setting the appropriate values in your own objects.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

homi wrote:
| Hi All,
|
| I am writing a Java code that uses a XML Config file to configure
| itself. Sample of the XML file has shown below. I want to have a peace
| of java code to reads that config file and import all the data to a
| class structure that I have designed before. In this case I will have
| a class name AppGroup and the whole config file will be stored in
| array of AppGroup objects. What is the best was of doing such a thing.
| I’ve already looked at Castor but seem to complicate to me.
| Thanks in advance for your help.
|
|
| <?xml version="1.0"?>
|
| <FConfig>
| <ExtraConf>
| <Name>TEST</Name>
| <Timeout>100</Timeout>
| </ExtraConf>
| <AppGroup>
| <Other>
| <AppName>BILL5</AppName>
| <FileSequenceIn>aaabbb</FileSequenceIn>
| <TransferAlarm>transAlarmCall</TransferAlarm>
| </Other>
| <TransConf>
| <Direction>INPUT</Direction>
| <SourceDir>/client/home/ttt</SourceDir>
| <FilePattern>aaavvv</FilePattern>
| <TargetDir>/home/rrr</TargetDir>
| <StateFile>auditState</StateFile>
| </TransConf>
| <TransConf>
| <Direction>OUTPUT</Direction>
| <SourceDir>/client/home/ggg</SourceDir>
| <FilePattern>aaaeee</FilePattern>
| <TargetDir>/home/yyy</TargetDir>
| <StateFile>auditState2</StateFile>
| </TransConf>
| </AppGroup>
| <AppGroup>
| ………………………..
| </AppGroup>
|
|
|
| Thanks,
|
| Homer


You could simply use a SAX parser to do it. Reading XML files using SAX
is easy, and there are a lot of tutorials on the net that show how to do
it. That would be my suggestion anyway :)


- --
[A n d r e w]
- ------|------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/hKQAx4nopx2ZsVURAgpHAJ95F+cW0xZGj9AAyP/LqkXPoPEAqQCfc1Js
EIi0yjXw8hs40yEkPkpWB14=
=pSBa
-----END PGP SIGNATURE-----
 
S

SPC

java.beans.XMLEncoder and java.beans.XMLDecoder. Will serialize a
vector straight off without you having to write any code IF the
objects in the vector have:
1. A default public constructor
2. public accessor methods for the object properties you want to
serialize OR the properties are public

No need to parse anything or load up an XML parser. It works much like
ObjectInputStream and ObjectOutputStream, except what you get is XML.

Regards

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top