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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:00:51+00:00 2026-05-22T01:00:51+00:00

I’m trying to fetch some XML and eventually use it as a String. Here’s

  • 0

I’m trying to fetch some XML and eventually use it as a String. Here’s my two methods, the former of which calls the latter.

public static void getAllXML(String url) throws XmlPullParserException, IOException, URISyntaxException{ 
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);

    XmlPullParser parser = factory.newPullParser(); 
    parser.setInput(new InputStreamReader(getUrlData(url)));  

    XmlUtils.beginDocument(parser,"results");

    int eventType = parser.getEventType();
    do{
        XmlUtils.nextElement(parser);
        parser.next();
        eventType = parser.getEventType();
        if(eventType == XmlPullParser.TEXT){
            Log.d("test",parser.getText());
        }
    } while (eventType != XmlPullParser.END_DOCUMENT) ;       

}

public static InputStream getUrlData(String url) throws URISyntaxException, ClientProtocolException, IOException {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet method = new HttpGet(new URI(url));
    HttpResponse res = client.execute(method);
    return  res.getEntity().getContent();

}

Then I use a method which takes an InputStream and converts it to a String. But how do I grab hold of the InputStream returned by the getUrlData method so I can call convertStreamToString(myInputStream)?

  • 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-22T01:00:52+00:00Added an answer on May 22, 2026 at 1:00 am

    You can use a TeeInputStream ( http://commons.apache.org/io/api-1.4/org/apache/commons/io/input/TeeInputStream.html ) to get the input stream that you pass to a parser and also write the input to a ByteArrayInputStream that you can then use with ByteArrayOutputStream.toString(String encoding).

    Something like

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    TeeInputStream is = new TeeInputStream(getDataUrl(...), bytes);
    try {
      // Pass is to parser here.
      parser.setInput(new InputStreamReader(is, "UTF-8"));
      // Note: please specify an encoding with InputStreamReader, maybe based on
      // the headers from getDataUrl.  
      ...
    } finally {
      is.close();
    }
    
    // After parsing finishes, convert the bytes to a String.
    String parsed = bytes.toString("UTF-8");
    // If UTF-8 is not appropriate, use the encoding specified in headers from URL.
    

    Alternatively, you can read the string in first, and then use a StringReader with parser.setInput. If your parser is set up to reject large inputs, or can take an InputStream as input and does charset detection that you might want to use later, then the approach above is more flexible.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.