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 7458801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:30:05+00:00 2026-05-29T13:30:05+00:00

I have the following XML retreived from webservices.How do i get the value of

  • 0

I have the following XML retreived from webservices.How do i get the value of StructureTransID i.e(254) from the above XML using XPath in android? Can anyone help me on this.

<Response>
−
<NewDataSet>
−
<EnrollmentList>
<Transaction_ID>369</Transaction_ID>
<Transaction_Key>489</Transaction_Key>
<Transaction_Type>ENROLLMENT_INFO</Transaction_Type>
<Corp_ID>2</Corp_ID>
−
<Transaction_Xml>
<EnrollmentInfo><SelectedPackages><Package Id="1-GQGFWG" Category="Medical" CoverageLevel="EMP_CHILDREN" CoverageAmt="355.11" TotalCoverageAmt="710.22" StructureTransID="254" EffectiveDate="01/01/2012" TerminationDate="12/31/2012" /></SelectedPackages><PersonalInfo><EmployeeID>E0211</EmployeeID><FirstName>Michael</FirstName><MiddleName /><LastName>Keaton</LastName><DateOfBirth>10/21/1975</DateOfBirth><Gender>M</Gender><SSN>123456789</SSN><Email>mkeaton@designllc.com</Email><AddressLine1>33 Park Street</AddressLine1><AddressLine2 /><AddressLine3 /><City>Jacksonville</City><State>FL</State><ZipCode>32220</ZipCode><HomePhone>(111) 222-4444</HomePhone><WorkPhone>(913) 244-8188</WorkPhone><Dependents><Dependent><FirstName>Alisha</FirstName><MiddleName /><LastName>Jones</LastName><DateOfBirth>1/13/2009</DateOfBirth><Gender>F</Gender><Relationship>Dependent</Relationship><AddressLine1>33 Park Street</AddressLine1><AddressLine2 /><AddressLine3 /><City>Jacksonville</City><State>FL</State><ZipCode>32220</ZipCode><HomePhone /><MedicareNumber /><PartA_EffectiveDate /><PartB_EffectiveDate /><IsFullTimeStudent>False</IsFullTimeStudent><CollegeName /><ExpectedGraduationDate /><CreditHours /></Dependent></Dependents></PersonalInfo><WorkInfo><Class>A004</Class><DateOfHire>05/01/2010</DateOfHire><Designation>Associate</Designation><WorkLocation>Canton</WorkLocation></WorkInfo><SelectedPackages /></EnrollmentInfo>
</Transaction_Xml>
<Active_Ind>1</Active_Ind>
<Effective_Date>2012-01-01T00:00:00+05:30</Effective_Date>
<Status>CO</Status>
<Created_On>2011-12-20T00:47:20.187+05:30</Created_On>
<Created_By>msmith</Created_By>
<Modified_On>2012-02-10T17:50:15.647+05:30</Modified_On>
<Modified_By>mkeaton</Modified_By>
<Termination_Date>2012-12-31T00:00:00+05:30</Termination_Date>
<Comments>Change in employment status</Comments>
<Task_ID>636</Task_ID>
<User_ID>489</User_ID>
<Import_ID>476</Import_ID>
<Corp_ID1>2</Corp_ID1>
<Employee_ID>E0211</Employee_ID>
<Login>mkeaton</Login>
<Password>cGFzc3dvcmQ=</Password>
<Full_Nm>Michael Keaton</Full_Nm>
<First_Nm>Michael</First_Nm>
<Middle_Nm/>
<Last_Nm>Keaton</Last_Nm>
<DOB>1975-10-21T00:00:00+05:30</DOB>
<Address_1>33 Park Street</Address_1>
<Address_2/>
<Address_3/>
<City>Jacksonville</City>
<State>FL</State>
<Postal_Code>32220</Postal_Code>
<Home_Phone_No>(111) 222-4444</Home_Phone_No>
<Work_Phone_No>(913) 244-8188</Work_Phone_No>
<Cell_Phone_No/>
<Email_Addr>mkeaton@designllc.com</Email_Addr>
<Login_Attempts_Cnt>0</Login_Attempts_Cnt>
<Login_Locked_Ind>0</Login_Locked_Ind>
<Allow_Internet_Use>1</Allow_Internet_Use>
<Active_Ind1>1</Active_Ind1>
<Hired_Dt>2010-05-01T00:00:00+05:30</Hired_Dt>
<Designation>Associate</Designation>
<Work_Location>Canton</Work_Location>
<SubGroup_ID>0001</SubGroup_ID>
<Created_On1>2011-12-20T00:44:04.577+05:30</Created_On1>
<Created_By1>msmith</Created_By1>
<Modified_On1>2012-02-10T17:50:10.343+05:30</Modified_On1>
<Modified_By1>mkeaton</Modified_By1>
<SSN>123456789</SSN>
<Class>A004</Class>
<Status1>A</Status1>
<EULA>1</EULA>
<Gender>M</Gender>
<ReAssignedToCobra>false</ReAssignedToCobra>
<ClassDesc>A004 - Management</ClassDesc>
</EnrollmentList>
</NewDataSet>
</Response>

I have tried this code in Java it works fine,but the same concept does not retreive the value in android.
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class XML {

    private NodeList nodelist;
    private static Element ele;

    public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder;
        Document doc = null;

        builder = factory.newDocumentBuilder();
        doc = builder.parse("/home/stella/person.xml");

        ele = doc.getDocumentElement();


          XPathFactory factor = XPathFactory.newInstance();
          XPath xpath = factor.newXPath();
          XPathExpression expr = xpath.compile("//Package");

          Object result = expr.evaluate(doc, XPathConstants.NODESET);
          NodeList nodes = (NodeList) result;
          for (int i = 0; i < nodes.getLength(); i++)
          {
              Node currentItem = nodes.item(i);
              String key = currentItem.getAttributes().getNamedItem("StructureTransID").getNodeValue();
              String value = currentItem.getTextContent();

              System.out.printf("%1s = %2s\n", key, value);
          }


    }


}
  • 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-29T13:30:06+00:00Added an answer on May 29, 2026 at 1:30 pm

    I copied your XML file to Notepad and tried to save it but it reported that “This file contains characters in Unicode format which will be lost if you save this file as an ANSI encoded text file.”. I let it proceed and then copied your program to a new Android project and it works! i.e. it does load your XML file and extract the “254” value.

    I then went back to the XML file and attempted to identify the weird characters and it led me to the 3 characters that look like minus signs, located at:

    <Response>
    −
    <NewDataSet>
    −
    ...
    −
    <Transaction_Xml>
    ...
    

    This got me to think that these characters aren’t minus signs, but, perhaps some weird encoding which is preventing it from working with the XML parser on Android. These characters, if correct, may need to be edited or migrated to an encoding that works with Android, perhaps UTF-8?

    Anyhow, I think this should give enough pointers on where to look.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML retrieved from a web service. How do I get
I have following xml and I want to fetch the value of node which
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I am using the following code to retrieve data from the xml file. It
I have a XML String retrieved from a XML file. I can't access the
I have following XML, and i wish to save its data in my SQL
I have following XML. I was able to remove all namespaces but not able
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have following xml as a response to a service not i want to
Currently I have following XML: <Rowsets> <Rowset> <Row> <DrilldownDepth>0</DrilldownDepth> <ScheduleWeek>---</ScheduleWeek> <ABC>---</ABC> <PQR>1500</PQR> <XYZ>15000</XYZ> <Quant>285</Quant>

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.