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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:51:23+00:00 2026-05-25T21:51:23+00:00

How to implement code for below xml file <root> <keys> <key> <Question>Is the color

  • 0

How to implement code for below xml file

<root>
  <keys>
    <key>
      <Question>Is the color of the car</Question>
      <Ans>black?</Ans>
    </key>
    <key>
      <Question>Is the color of the car</Question>
      <Ans>black?</Ans>
    </key>
    <key>
      <Question>Is the news paper </Question>
      <Ans>wallstreet?</Ans>
    </key>
    <key>
      <Question>fragrance odor</Question>
      <Ans>Lavendor?</Ans>
    </key>
    <key>
      <Question>Is the baggage collector available</Question>
      <Ans></Ans>
    </key>
  </keys>
</root>

Display on the screen as:

List form
Is the color of the car black? Check box
Is the baggage collector available? Check box

If the check box is checked – Yes otherwise value is no.

On save button: we need to save it into a xml file. So any one help me to solve the problem.

  • 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-25T21:51:24+00:00Added an answer on May 25, 2026 at 9:51 pm

    By your question it appears you want to fetch contents of XML. For that you need to parse the XML. Create an XMLClass.java

    public class XMLfunctions {
    
    public final static Document XMLfromString(String xml){
    
        Document doc = null;
    
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
    
            DocumentBuilder db = dbf.newDocumentBuilder();
    
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is); 
    
        } catch (ParserConfigurationException e) {
            System.out.println("XML parse error: " + e.getMessage());
            return null;
        } catch (SAXException e) {
            System.out.println("Wrong XML file structure: " + e.getMessage());
            return null;
        } catch (IOException e) {
            System.out.println("I/O exeption: " + e.getMessage());
            return null;
        }
    
        return doc;
    
    }
    
    /** Returns element value
      * @param elem element (it is XML tag)
      * @return Element value otherwise empty String
      */
     public final static String getElementValue( Node elem ) {
         Node kid;
         if( elem != null){
             if (elem.hasChildNodes()){
                 for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
                     if( kid.getNodeType() == Node.TEXT_NODE  ){
                         return kid.getNodeValue();
                     }
                 }
             }
         }
         return "";
     }
    
     public static String getXML(int s, int y){  
            String line = null;
    
            try {
    
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String link = "//YOUR URL HERE" add LIMITS IF ANY
                     for ex: String link = "www.ab.com/index.php?action=gq&start="+s+"&limit="+y;
    // it will give you values from 1 to 10 or 1 to 50 whatever you mention         
                HttpPost httpPost = new HttpPost(link);
    
                System.out.println("Httppost="+httpPost);
    
                HttpResponse httpResponse = httpClient.execute(httpPost);
    
                HttpEntity httpEntity = httpResponse.getEntity();
    
                System.out.println("HttpEntity="+httpEntity);
    
                line = EntityUtils.toString(httpEntity);
    
                System.out.println("Line="+line);
    
            } catch (UnsupportedEncodingException e) {
                line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
            } catch (MalformedURLException e) {
                line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
            } catch (IOException e) {
                line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
            }
    
            return line;
    
    }
    

    Then in other class call this getXML function

    declare int s and int y with some value

       String xmls = XMLfunctions2.getXML(loginid);    
    
        Document docs = XMLfunctions2.XMLfromString(xmls);
        NodeList node = docs.getElementsByTagName("start");
    
    for (int i = 0; i < node.getLength(); i++) {    
    
            org.w3c.dom.Element e = (org.w3c.dom.Element)node.item(i);
            if(i==0)
    
            {
                quest= XMLfunctions.getValue(e, "Question");
                ans=XMLfunctions.getValue(e, "Answer");
                key=XMLfunctions.getValue(e, "key");
    
            }
    

    }

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

Sidebar

Related Questions

Given the code below, how would you create/implement SR.h so that it produces the
I would like to implement a parallel version of the code below using threads
I'm trying to implement file upload functionality in the iPhone app. Server code is
I've got code as below: class ListPageXMLFiles implements FileFilter { @Override public boolean accept(File
Below is the my complete code Here is cfg file <hibernate-configuration> <session-factory> <!-- Database
I'm struggling to convert the below code to C#. Class Class1 Implements IMyInterface Public
Firefox apparently supports a PING attribute for HREFs. How do I implement code to
I've been asked to implement some code that will update a row in a
I am working in C to implement pseudo-code that says: delay = ROUND(64*(floatDelay -
I've searched the forum, and tried to implement the code in the threads I

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.