mapping xml to a class or array

Hi i am wondering if it is possible to map an xml file to a java class or an array i have the following xml file and would like the Dom to be mapped to an array i have checked castor xml mapping but this site is not very clear can i map the following xml

<program>
<decs>
<decl>int rand1=0</decl>
<decl>int rand2=0</decl>
<decl>int rand3=0</decl>
</decs>
<program>

if this is possible how would this be done i am using dom
donnaeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You can use commons Digester to do this
radarshCommented:
with digester, I doubt if you can write back XML from java objects... well, i'm not sure.
One thing I am sure about is Castor.

http://www.castor.org

________
radarsh
CEHJCommented:
>>with digester, I doubt if you can write back XML from java objects.

Is that required?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Mick BarryJava DeveloperCommented:
donnaeAuthor Commented:
No i just want to add the text in the xml file to an array or class and output the results in an application... the class or array with int rand1=0, i want to call a method to randomly generate a character to replace the text rand1 which will then become int a=0.

Mick BarryJava DeveloperCommented:
xpath will do that 4u
donnaeAuthor Commented:
with xpath can you specify which elements you wish to select. im not so sure how to use xpath quite new to xml, does xpath have to be in an xsl file???
CEHJCommented:
XPath won't help you if you need xml to object marshalling. That's what digester is designed for
Mick BarryJava DeveloperCommented:
>  with xpath can you specify which elements you wish to select.

yes, that what it is for

> does xpath have to be in an xsl file???

no

> XPath won't help you if you need xml to object marshalling.

That is not required. Strange that you fabricate requirements after putting down an earlier suggestrion for the same thing. You've made your suggestion, please leave others to make their own.
CEHJCommented:
>>That is not required.

Seems to be to me:

>>am wondering if it is possible to map an xml file to a java class or an array
Mick BarryJava DeveloperCommented:
object marshalling is not required to achieve that, xpath can do that just fine
javaoptimizerCommented:
Hi , you can easily map this to a java class using CASTOR.

i.e in your class you can have String array[] to which you can map the values.

<?xml version="1.0" encoding="UTF-8"?>
<mapping>
    <class name="yourclassname" auto-complete="false">
        <description>Default mapping for class </description>
        <map-to xml="Program"/>
        <field name="rand" type="String" Collection="array"  required="true" direct="false" transient="false">
            <bind-xml name="decl" node="element" matches="Header" reference="false" location="decls/decl"/>
        </field>
    </class>
</mapping>

i think this mapping will work , but i havent tested , just check out the values of location tags and bind-xml name.
Any Doubts please do ask me
NoOodiCommented:
This Site contains an example. it will be very useful:
http://www.developerfusion.co.uk/show/2064/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.