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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:51:11+00:00 2026-06-14T12:51:11+00:00

I have the following xml: <version> <name>2.0.2</name> <description> -Stop hsql database after close fist

  • 0

I have the following xml:

<version>
    <name>2.0.2</name>
    <description>
-Stop hsql database after close fist <br />
-Check for null category name before adding it to the categories list  <br />
-Fix NPE bug if there is no updates  <br />
-add default value for variable, change read bytes filter, and description of propertyFile  <br />
-Change HTTP web Proxy (the “qcProxy” field ) to http://web-proxy.isr.hp.com:8080  <br />
</description>
    <fromversion>>=2.0</fromversion>
</version>

I want to return description tag string content using Java?

  • 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-14T12:51:12+00:00Added an answer on June 14, 2026 at 12:51 pm

    This is pretty standard Java XML parsing, you can find it anywhere on the internet, but it goes like this using XPath in standard JDK.

    String xml = "your XML";
    
    // load the XML as String into a DOM Document object
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
    Document doc = docBuilder.parse(bis);
    
    // XPath to retrieve the content of the <version>/<description> tag
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("/version/description");
    Node description = (Node)expr.evaluate(doc, XPathConstants.NODE);
    System.out.println("description: " + description.getTextContent());
    

    Edit

    Since you are having XML <br/> in your text content, it cannot be retrieved from Node.getTextContent(). One solution is to transform that Node to XML String equivalent, stripping the root node <description>.

    This is a complete example:

    String xml = "<version>\r\n" + //
            "    <name>2.0.2</name>\r\n" + //
            "    <description>\r\n" + //
            "-Stop hsql database after close fist <br />\r\n" + //
            "-Check for null category name before adding it to the categories list  <br />\r\n" + //
            "-Fix NPE bug if there is no updates  <br />\r\n" + //
            "-add default value for variable, change read bytes filter, and description of propertyFile  <br />\r\n" + //
            "-Change HTTP web Proxy (the “qcProxy” field ) to http://web-proxy.isr.hp.com:8080  <br />\r\n" + //
            "</description>\r\n" + //
            "    <fromversion>>=2.0</fromversion>\r\n" + //
            "</version>";
    
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
    Document doc = docBuilder.parse(bis);
    
    // XPath to retrieve the <version>/<description> tag
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("/version/description");
    Node descriptionNode = (Node) expr.evaluate(doc, XPathConstants.NODE);
    
    // Transformer to convert the XML Node to String equivalent
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringWriter sw = new StringWriter();
    transformer.transform(new DOMSource(descriptionNode), new StreamResult(sw));
    String description = sw.getBuffer().toString().replaceAll("</?description>", "");
    System.out.println(description);
    

    prints:

    -Stop hsql database after close fist <br/>
    -Check for null category name before adding it to the categories list  <br/>
    -Fix NPE bug if there is no updates  <br/>
    -add default value for variable, change read bytes filter, and description of propertyFile  <br/>
    -Change HTTP web Proxy (the “qcProxy” field ) to http://web-proxy.isr.hp.com:8080  <br/>
    

    Edit 2

    In order to have them all you need to get a NODESET of the different nodes and iterate over it to do the exact same operation as above.

    // XPath to retrieve the content of the <version>/<description> tag
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("//description");
    NodeList descriptionNode = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    
    List<String> descriptions = new ArrayList<String>(); // hold all the descriptions as String
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    for (int i = 0; i < descriptionNode.getLength(); ++i) {
        Node descr = descriptionNode.item(i);
        StringWriter sw = new StringWriter();
        transformer.transform(new DOMSource(descr), new StreamResult(sw));
        String description = sw.getBuffer().toString().replaceAll("</?description>", "");
        descriptions.add(description);
    }
    // here you can do what you want with the List of Strings `description`
    
    • 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: <?xml version=1.0 encoding=UTF-8?> <game> <name>Space Blaster</name> <description></description> <version>1</version> <fullscreen>false</fullscreen>
I'm working with a legacy database and have following mappings: PersonBase: <?xml version=1.0 encoding=utf-8
I have the following XML <map version=1.0> <properties> <property name=color value=blue /> <property name=size
I have the following XML <?xml version=1.0 encoding=ISO-8859-1 ?> - <DEVICEMESSAGES> <VERSION xml=1 checksum=
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following simplified XML: <?xml version="1.0" encoding="UTF-8" ?> <MATMAS05> <IDOC BEGIN="1"> <E1MARAM
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">
I have the following xsd files: SchemaA <?xml version=1.0 encoding=utf-8?> <xs:schema targetNamespace=http://schemaA elementFormDefault=qualified xmlns=http://schemaA
In my web.xml I have the following mapping <servlet-mapping> <servlet-name>mySite</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>mySite</servlet-name>
I have the following xml: <?xml version=1.0?> <catalog> <book id=bk101> <author>Gambardella, Matthew</author> <title>XML Developer'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.