aditya
aditya

Reputation: 495

parsing xml to java object

i want to pick a perticular node from an XMl file and then parse it to a java Object

for eg my sample.xml file is as follows

<?xml version="1.0" encoding="UTF-8"?>
 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
    <ns2:GetStudyInfo xmlns:ns2="http://com.study/">
        <WSResult>
            <ResultCode>eMaven-0000</ResultCode>
            <ResultDesc>Ok</ResultDesc>
        </WSResult>
        <return>
            <StudyNumber>Q005</StudyNumber>
            <StudyTitle>Stomach</StudyTitle>
            <StudyPI></StudyPI>
            <eirbNumber></eirbNumber>
            <SponsorID></SponsorID>
            <SponsorName></SponsorName>
            <SponsorContact></SponsorContact>
            <OtherInfo></OtherInfo>
            <StudyDiv></StudyDiv>
            <StudyID>904</StudyID>
            <StudyStatus></StudyStatus>
            <RevBoard></RevBoard>
            <InitalAppDate>01-01-1900</InitalAppDate>
        </return>
        <return>
            <StudyNumber>Q004</StudyNumber>
            <StudyTitle>Brain Tumor</StudyTitle>
            <StudyPI></StudyPI>
            <eirbNumber></eirbNumber>
            <SponsorID></SponsorID>
            <SponsorName></SponsorName>
            <SponsorContact></SponsorContact>
            <OtherInfo></OtherInfo>
            <StudyDiv>Cardiology</StudyDiv>
            <StudyID>891</StudyID>
            <StudyStatus>Active/Enrolling</StudyStatus>
            <RevBoard></RevBoard>
            <InitalAppDate>01-01-1900</InitalAppDate>
        </return>

    </ns2:GetStudyInfo>
</S:Body>

now what my requirement is to take the "return" node and then take its all element in a java object.

want to use JAXB annotation base work.

please help.

Thanks

Upvotes: 1

Views: 294

Answers (2)

Siva Arunachalam
Siva Arunachalam

Reputation: 7740

Use SAX and take the return and for JAX-B, You can start with the following link

http://docs.oracle.com/cd/E12840_01/wls/docs103/webserv/data_types.html

Upvotes: 0

Puce
Puce

Reputation: 38132

You can filter the node with e.g. XSL or the StaX API. Then use JAXB to unmarshal the object.

Upvotes: 1

Related Questions