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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:43:29+00:00 2026-05-16T21:43:29+00:00

I have an input stream which is being converted to XML, and read. When

  • 0

I have an input stream which is being converted to XML, and read. When I get down to some text elements in the XML, they are truncated. I believe the parser is dropping everything after escaped HTML such as & Here is the code getting the input stream and then getting the text element.

String hvurl = "https://www.mysite.com/api/a/" + answerId;
in = OpenHttpConnection(hvurl); 

Document doc = null;
DocumentBuilderFactory dbf = 
    DocumentBuilderFactory.newInstance();
DocumentBuilder db;

try {
    db = dbf.newDocumentBuilder();
    doc = db.parse(in);

} catch (ParserConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (SAXException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}     

...
//Now when I get the text element, it's truncated
//---get the <varietalTitle> elements under the <varietal> 
// element---
NodeList varietalTitleNodes = 
    (varietalElement).getElementsByTagName("varietaltitle");

//---convert a Node into an Element---
Element varietalTitleElement = (Element) varietalTitleNodes.item(0);

//---get all the child nodes under the <varietaltitle> element---
NodeList varietalTitleTextNodes = 
    ((Node) varietalTitleElement).getChildNodes();

//---retrieve the text of the <varietalid> element---
strVarietalTitle = ((Node) varietalTitleTextNodes.item(0)).getNodeValue();
  • 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-16T21:43:29+00:00Added an answer on May 16, 2026 at 9:43 pm

    Cant get where the problem occurs. My guess use the normalize() method as below.

    Try this:

     strVarietalTitle = ((Node) varietalTitleTextNodes.item(0)).getNodeValue().normalize();
    

    From documentation Normalize():

    Puts Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a “normal” form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer [XPointer] lookups) that depend on a particular document tree structure are to be used. If the parameter “normalize-characters” of the DOMConfiguration object attached to the Node.ownerDocument is true, this method will also fully normalize the characters of the Text nodes.
    Note: In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

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

Sidebar

Related Questions

I have some code which I think should compile, but doesn't: import java.io.InputStream; import
I have an input stream, and I want to map to output lines. For
I have been testing the performance of reading server socket input stream. I found
So a FILE stream can have both input and output buffers. You can adjust
I have input text: <div><label wicket:for=name>Name</label><input type=text wicket:id=name /></div> Now I need to add
i have input xml as <content> <date> <day>14</day> <month>06</month> <year>2012</year> </date> </content> want it
I'm making an application in which I have to do XML parsing. I have
Currently, I have a String object that contains XML elements: String carsInGarage = garage.getCars();
I'm trying to figure out how to read from the standard input stream of
I have input.txt and I want to search for a string and extract a

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.