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

  • Home
  • SEARCH
  • 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 8581289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:00:44+00:00 2026-06-11T21:00:44+00:00

I just learn how to working with ListView and parsing XML data in Java

  • 0

I just learn how to working with ListView and parsing XML data in Java following this tutorial. However, I’m getting an error because the XML data contains some special characters. Could someone kindly advice me on this issue?

This is my XML Data looks like.

<menu>

<item>      
    <id>1</id>
    <question>What's my phone number?</question>
    <answer>my phone number is "000-000-0000".</answer>        
</item>  

<item>      
    <id>2</id>
    <question>What's my fax number?</question>
    <answer>my fax number is "000-000-0000"</answer>        
</item>  

<item>      
    <id>3</id>
    <question>What's my mailing address?</question>
    <answer>my address here</answer>        
</item> 

<item>      
    <id>4</id>
    <question>What's my web address?</question>
    <answer>https://mywebsite.com/Login/Login.aspx?cID=53044&lng=en-US</answer>        
</item> 

</menu>

And here is the Java class.

public class FaqsQuestionsActivity extends ListActivity {


    static final String URL = "http://myweb.com/faq_list.xml";
    // XML node keys
    static final String KEY_ITEM = "item"; // parent node   
    static final String KEY_ID = "id";
    static final String KEY_QUESTION = "question";
    static final String KEY_ANSWER = "answer";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.faqs_questions);

        ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_ITEM);

        for (int i = 0; i < nl.getLength(); i++) {

            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);

            map.put(KEY_ID, parser.getValue(e, KEY_ID));
            map.put(KEY_QUESTION, parser.getValue(e, KEY_QUESTION ));
            map.put(KEY_ANSWER, parser.getValue(e, KEY_ANSWER));

            menuItems.add(map);
        }

        ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.faqs_question_list,
        new String[] { KEY_QUESTION, KEY_ANSWER  }, new int[] {R.id.question, R.id.answer});


        setListAdapter(adapter);

        ListView lv = getListView();

        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


                String question = ((TextView) view.findViewById(R.id.question)).getText().toString();
                String answer = ((TextView) view.findViewById(R.id.answer)).getText().toString();


                Intent in = new Intent(getApplicationContext(), FaqsAnswersActivity.class);

                in.putExtra(KEY_QUESTION, question);
                in.putExtra(KEY_ANSWER, answer);
                startActivity(in);

            }
        });
    }
}
  • 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-06-11T21:00:45+00:00Added an answer on June 11, 2026 at 9:00 pm

    You can try to encode your XML before trying to parse it:

    String encodedXML = URLEncoder.encode(xml);
    

    And then parse.

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

Sidebar

Related Questions

I'm just starting to learn backbone.js. I'm following this tutorial here at backbonetutorials.com, but
I'm working on a twisted tutorial just to learn more python and it seems
I'm working on a project (simple XML CMS) just to learn some basic PHP.
im just starting to learn LINQ and at the same time im working on
I am doing some tests, just to learn (normally i do this in ajax
I'm doing this with a very simple class, just to learn, but I'm not
So i've been working on a MVC2 application just to learn the ropes really.
I am working on an interpreter for a toy language, just to learn about
I've just started to learn the long-heard python language. I've been working with C
Working my way through Learn Python the Hard Way ex.25, and I just can't

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.