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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:15+00:00 2026-05-25T23:28:15+00:00

I trying to parse xml from an inputstream using the sax parser. The inputstream

  • 0

I trying to parse xml from an inputstream using the sax parser. The inputstream get incoming xml continously from a socket. ‘\n’ is used as a delimiter between xml data. This is how the xml would look like

<?xml version="1.0" encoding="UTF-8"?>
<response processor="header" callback="comheader">
    <properties>
        <timezone>Asia%2FBeirut</timezone>
        <rawoffset>7200000</rawoffset>
        <to_date>1319256000000</to_date>
        <dstrawoffset>10800000</dstrawoffset>
    </properties>
</response>
\n
<event type="progress" time="1317788744214">
    <param key="callback">todayactions</param>
    <param key="percent">10</param>
    <param key="msg">MAPPING</param>
</event>
<event type="progress" time="1317788744216">
    <param key="callback">todayactions</param>
    <param key="percent">20</param><param key="msg">MAPPING</param>
</event>
\n
<?xml version="1.0" encoding="UTF-8"?>
<response processor="header" callback="comheader">
    <properties>
        <timezone>Asia%2FBeirut</timezone>
        <rawoffset>7200000</rawoffset>
        <to_date>1319256000000</to_date>
        <dstrawoffset>10800000</dstrawoffset>
    </properties>
</response>

This worked perfectly for the our iphone project as we took the characters upto \n and stored that in a string and used the dom parser.

But when I tried to do this for the android, string was not an option as it gave us OutOfMemory exception. So we set the inputstream directly to the SaxParser it works until the \n character, after that it gives us the exception

org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column
0: junk after document element

So I tried to filter the inputstream to skip the ‘\n’ character. I created a FilterStreamReader but I was not successful, it seems my read function isn’t doing the job. Here is my code.

public class FilterStreamReader extends InputStreamReader {
    public FilterStreamReader(InputStream in, String enc)
            throws UnsupportedEncodingException {
        super(in, enc);
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
        int read = super.read(cbuf, off, len);
        Log.e("Reader",Character.toString((char)read));
        if (read == -1) {
            return -1;
        }

        int pos = off - 1;
        for (int readPos = off; readPos < off + read; readPos++) {
            if (read == '\n') {
                pos++;
            } else {                
                continue;
            }
            if (pos < readPos) {
                cbuf[pos] = cbuf[readPos];
            }
        }
        return pos - off + 1;
}

Can someone help me filter the \n of an inputstream?

Edit
Based on what graham said I was able to parse the whole data by removing all the doc types and adding my own start and end tag. So Im not really sure that my problem is not filtering ‘\n’ alone. How can you parse xml that keeps coming like this?

  • 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-25T23:28:15+00:00Added an answer on May 25, 2026 at 11:28 pm

    The problem isn’t the \n. It’s that after the first </response> tag, it thinks the document is complete.

    This data isn’t valid XML. You should wrap everything inside a single top-level node. Also, you can’t have a second <?xml version="1.0" encoding="UTF-8"?> declaration part-way through the document.

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

Sidebar

Related Questions

I'm trying to parse xml from SharePoint service (lists) using jquery. I have XMLHttpRequest
I am trying to parse XML feeds from YouTube using jQuery (by doing $(xml).find(...)
I'm trying to parse the XML HttpResponse i get from a HttpPost to a
I am trying to parse an xml file using SAX with Android and the
I am new to jquery. I am trying to parse xml string using jquery.
I'm trying to parse XML returned from the Youtue API. The APIcalls work correctly
So I'm trying to parse some XML from the twitter API and for some
I'm trying to parse an xml file from a website. Let's say the website
I am trying to parse an XML response from a website in C#. The
I am getting this error while trying to Parse the Xml response from the

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.