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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:27:01+00:00 2026-05-27T08:27:01+00:00

I have XML in the form of a String that contains <message>HELLO!</message> How can

  • 0

I have XML in the form of a String that contains

<message>HELLO!</message> 

How can I get the String “Hello!” from the XML? It should be ridiculously easy but I am lost. The XML isn’t in a doc, it is simply a String.

  • 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-27T08:27:02+00:00Added an answer on May 27, 2026 at 8:27 am

    Using JDOM:

    String xml = "<message>HELLO!</message>";
    org.jdom.input.SAXBuilder saxBuilder = new SAXBuilder();
    try {
        org.jdom.Document doc = saxBuilder.build(new StringReader(xml));
        String message = doc.getRootElement().getText();
        System.out.println(message);
    } catch (JDOMException e) {
        // handle JDOMException
    } catch (IOException e) {
        // handle IOException
    }
    

    Using the Xerces DOMParser:

    String xml = "<message>HELLO!</message>";
    DOMParser parser = new DOMParser();
    try {
        parser.parse(new InputSource(new java.io.StringReader(xml)));
        Document doc = parser.getDocument();
        String message = doc.getDocumentElement().getTextContent();
        System.out.println(message);
    } catch (SAXException e) {
        // handle SAXException 
    } catch (IOException e) {
        // handle IOException 
    }
    

    Using the JAXP interfaces:

    String xml = "<message>HELLO!</message>";
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    try {
        db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        try {
            Document doc = db.parse(is);
            String message = doc.getDocumentElement().getTextContent();
            System.out.println(message);
        } catch (SAXException e) {
            // handle SAXException
        } catch (IOException e) {
            // handle IOException
        }
    } catch (ParserConfigurationException e1) {
        // handle ParserConfigurationException
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .xslt that translates xml from one form to another (I'm not
In my C# app I get an xml from a server that contains some
I have an xml in the form of a string. Let's say that the
I have dynamically created a xml string form a JSON object returned from server.
I have an XML form with an element 0, which is well-formed but not
I currently have a datasource from a client in the form of XML, this
I have XML files in a directory that I wish to get over to
I have the following code that returns rows from a database when a form
I have some XML that stores column information and row data from a table
I am trying to create form that contains another model in rails. I have

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.