Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:11:02+00:00 2026-05-25T02:11:02+00:00

I am consuming a web service as its output is an XML string. I

  • 0

I am consuming a web service as its output is an XML string. I am parsing it into a document and getting each child node value one by one and inserting into my SQLlite table as shown below:

public void DownloadAndInsertProblemAndReasonCode(String serverIPAddress,
            String deviceId) {
        String SOAP_ACTION = "http://VisionEPODWebService/GetProblemAndReasonCodesNew";
        String OPERATION_NAME = "GetProblemAndReasonCodesNew";
        String WSDL_TARGET_NAMESPACE = "http://VisionEPODWebService/";
        String SOAP_ADDRESS = "";

        SOAP_ADDRESS = "http://" + serverIPAddress
                + "/VisionEPODWebService/SystemData.asmx";
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
                OPERATION_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER10);
        request.addProperty("deviceID", deviceId);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        try {
            httpTransport.call(SOAP_ACTION, envelope);
            Object response = envelope.getResponse();
            DocumentBuilderFactory docBuilberFactory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder docBuilder = docBuilberFactory.newDocumentBuilder();
            InputSource inputSource = new InputSource();
            inputSource
                    .setCharacterStream(new StringReader(response.toString()));
            Document doc = docBuilder.parse(inputSource);
            NodeList nodesProblemCode = doc
                    .getElementsByTagName("tblProblemCode");
            ContentValues initialProblemCodeValues = new ContentValues();
            dbAdapter = new DatabaseAdapter(this.context);
            dbAdapter.open();
            dbAdapter.BeginTransaction();
            dbAdapter.DeleteRecord("tblProblemCode", "", "");

            for (int i = 0; i < nodesProblemCode.getLength(); i++) {
                Element element = (Element) nodesProblemCode.item(i);

                NodeList PKProblemCode = element
                        .getElementsByTagName("PKProblemCode");
                Element line = (Element) PKProblemCode.item(0);
                initialProblemCodeValues.put("PKProblemCode",
                        getCharacterDataFromElement(line).toString());

                NodeList ProblemCode = element
                        .getElementsByTagName("ProblemCode");
                line = (Element) ProblemCode.item(0);
                initialProblemCodeValues.put("ProblemCode",
                        getCharacterDataFromElement(line));

                NodeList ProblemCodeDescription = element
                        .getElementsByTagName("ProblemCodeDescription");
                line = (Element) ProblemCodeDescription.item(0);
                initialProblemCodeValues.put("ProblemCodeDescription",
                        getCharacterDataFromElement(line).toString());

                NodeList VWReturn = element.getElementsByTagName("VWReturn");
                line = (Element) VWReturn.item(0);
                initialProblemCodeValues.put("VWReturn",
                        getCharacterDataFromElement(line).toString());

                dbAdapter.InsertRecord("tblProblemCode", "",
                        initialProblemCodeValues);
            }

            NodeList nodesReasonCode = doc
                    .getElementsByTagName("tblReasonCode");
            ContentValues initialReasonCodeValues = new ContentValues();
            dbAdapter.DeleteRecord("tblReasonCode", "", "");
            for (int i = 0; i < nodesReasonCode.getLength(); i++) {
                Element element = (Element) nodesReasonCode.item(i);

                NodeList PKReasonCode = element
                        .getElementsByTagName("PKReasonCode");
                Element line = (Element) PKReasonCode.item(0);
                initialReasonCodeValues.put("PKReasonCode",
                        getCharacterDataFromElement(line).toString());

                NodeList ReasonDescription = element
                        .getElementsByTagName("ReasonDescription");
                line = (Element) ReasonDescription.item(0);
                initialReasonCodeValues.put("ReasonDescription",
                        getCharacterDataFromElement(line));

                dbAdapter.InsertRecord("tblReasonCode", "",
                        initialReasonCodeValues);
            }
            dbAdapter.SetSucessfulTransaction();
            dbAdapter.EndTransaction();
            dbAdapter.close();
        }

        catch (Exception exception) {
            exception.toString();
        }

    }


public static String getCharacterDataFromElement(Element e) {

        Node child = e.getFirstChild();
        if (child instanceof CharacterData) {
            CharacterData cd = (CharacterData) child;
            return cd.getData();
        }
        return "?";
    }

The problem is that after some time the XML string will not have some of child node. For example
“ProblemCode” child node…..at that time the code shows error.

How can I check whether there exists an element in the document, or whether values exist or not for the element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:11:03+00:00Added an answer on May 25, 2026 at 2:11 am

    I think you need to check if the child node exists: specifically for your problem node:

    NodeList NL = element.getElementsByTagName("PKProblemCode");
    if ((NL==null)||(NL.getLength()==0)) {
      //No such node so use a default instead
    } else 
      Element line = (Element) PKProblemCode.item(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when ever i am consuming a web service xml is received and sent right...is
I'm consuming a web service using a stand-alone VBScript. The web service returns to
I'm consuming a web service from C#, and the web service requires a login
I have a web service that is protected by requiring the consuming third party
I am consuming an external C# Web Service method which returns a simple calculation
I'm consuming a third-party resource (a .dll) in a web service, and my problem
I have a problem with consuming a third-party web service in .NET C#. It
I have two WCF clients consuming a 3rd party web service. These two clients
I am consuming a WCF Service from a webpart in Sharepoint 2007. But its
I am consuming a web service in .NET application with WCF client. The Endpoint's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.