0

I have a situation where i am confused how to parse the XML dynamically. I am using soap web service, where i want to get only method from request xml and i want to show only result according to the response xml.

Situation-1

My request

<soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:ncog="http://ncogroup.com/">
        <soapenv:Header/>
        <soapenv:Body>
            <ncog:IVR_OtsukaAbilifyRegister>
                <ncog:Q_ZIP>?</ncog:Q_ZIP>
                <ncog:Q_DOB>?</ncog:Q_DOB>
                <ncog:Q_PIN>?</ncog:Q_PIN>
                <ncog:Q_COUNTRY>?</ncog:Q_COUNTRY>
                <ncog:Q_RESIDENT>?</ncog:Q_RESIDENT>
                <ncog:Q_GOVT_PAID>?</ncog:Q_GOVT_PAID>
                <ncog:Q_MED_ACK>?</ncog:Q_MED_ACK>
                <ncog:Q_PERM_OPT_IN>?</ncog:Q_PERM_OPT_IN>
                <ncog:Q_MARKETING_OPT_IN>?</ncog:Q_MARKETING_OPT_IN>
                <ncog:Q_ABILIFY_60>?</ncog:Q_ABILIFY_60>
                <ncog:Q_DRUG_COVERAGE>?</ncog:Q_DRUG_COVERAGE>
                <ncog:Q_SOURCE>?</ncog:Q_SOURCE>
                <ncog:Q_DATA_OPT_IN>?</ncog:Q_DATA_OPT_IN>
            </ncog:IVR_OtsukaAbilifyRegister>
        </soapenv:Body>
    </soapenv:Envelope>

My response

<soap:Envelope
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
            <IVR_OtsukaAbilifyRegisterResponse
                xmlns="http://ncogroup.com/">
                <IVR_OtsukaAbilifyRegisterResult>
                    <TriplefinResultCode>P02</TriplefinResultCode>
                    <Msg>Index was outside the bounds of the array.</Msg>
                </IVR_OtsukaAbilifyRegisterResult>
            </IVR_OtsukaAbilifyRegisterResponse>
        </soap:Body>
    </soap:Envelope>

In this above example i want IVR_OtsukaAbilifyRegister as my method and my response Index was outside the bounds of the array.

i have tried below code, but i can't able to get perfect data

private Document parseXmlFile() {
        String in = readFile();
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource(new StringReader(in));
            return db.parse(is);
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        } catch (SAXException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Sangram Badi
  • 4,054
  • 9
  • 45
  • 78

0 Answers0