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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:28:08+00:00 2026-06-06T12:28:08+00:00

Is it feasible in Java using the SAX api to parse a list of

  • 0

Is it feasible in Java using the SAX api to parse a list of XML fragments with no root element from a stream input?

I tried parsing such an XML but got a

org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.

before even the endDocument event was fired.

I would like not to settle with obvious but clumsy solutions as “Pre-append a custom root element or Use buffered fragment parsing”.

I am using the standard SAX API of Java 1.6. The SAX factory had setValidating(false) in case anyone wondered.

  • 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-06T12:28:11+00:00Added an answer on June 6, 2026 at 12:28 pm

    First, and most important of all, the content you are parsing is not an XML document.
    From the XML Specification:

    [Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element.]

    Now, as to parsing this with SAX – in spite of what you said about clumsiness – I’d suggest the following approach:

    Enumeration<InputStream> streams = Collections.enumeration(
        Arrays.asList(new InputStream[] {
            new ByteArrayInputStream("<root>".getBytes()),
            yourXmlLikeStream,
            new ByteArrayInputStream("</root>".getBytes()),
        }));
    
    SequenceInputStream seqStream = new SequenceInputStream(streams);
    
    // Now pass the `seqStream` into the SAX parser.
    

    Using the SequenceInputStream is a convenient way of concatenating multiple input streams into a single stream. They will be read in the order they are passed to the constructor (or in this case – returned by the Enumeration).

    Pass it to your SAX parser, and you are done.

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

Sidebar

Related Questions

I am using jni4net to access Java code from within a C# application, and
I'm using a Java DatagramSocket to stream data to multiple different clients. As I
I'm using lucene indexes for a search feature in an application in Java. Deleting
I have a simple java applet that retrieves an image from a server and
I am develop a web app (using Java EE 6 with GF 3.1) that
Mac OS 10.7 (Lion) comes with JDK 1.6 and java 6. Is it feasible
How do i set cookie in the request while invoking a java webservice from
Do you know of a way to interrupt a read from a Java InputStream
I am invoking a javascript function for drilling down the chart. I tried using
Is there any easy reasonable/feasible way to efficiently pipeline results from the database? I

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.