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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:29:12+00:00 2026-05-24T10:29:12+00:00

I have a process that parses an XML file using JDOM and xpath to

  • 0

I have a process that parses an XML file using JDOM and xpath to parse the file as shown below:

private static SAXBuilder   builder         =   null;
private static Document     doc         =   null; 
private static XPath        xpathInstance       =   null;

builder = new SAXBuilder();
Text list = null;

try {
    doc = builder.build(new StringReader(xmldocument));

} catch (JDOMException e) {
            throw new Exception(e);
} 



try {
    xpathInstance = XPath.newInstance("//book[author='Neal Stephenson']/title/text()");
    list = (Text) xpathInstance.selectSingleNode(doc);
} catch (JDOMException e) {
    throw new Exception(e);
}

The above works fine. The xpath expressions are stored in a properties file so these can be changed anytime. Now i have to process some more xml files that come from a legacy system that will only send the xml files in chunks of 4000 bytes. The existing processing reads the 4000 byte chunks and stores them in an Oracle database with each chunk as one row in the database (Making any changes to the legacy system or the processing that stores the chunks as rows in the database is out of the question).

I can build the complete valid XML document by extracting all the rows related to a specific xml document and merging them and then use the existing processing (shown above) to parse the xml document.

The thing is though, the data i need to extract from the XML document will always be on the first 4000 bytes. This chunk ofcourse is not a valid XML document as it will be incomplete but will contain all the data i need. I cant parse just the one chunk as the JDOM builder will reject it.

I am wondering whether i can parse the malformed XML chunk without having to merge all parts (which could get to quite many) in order to get a valid XML document. This will save me several trips to the database to check if a chunk is available and i wont have to merge 100s of chunks only for being able to use the first 4000 bytes.

I know i could probably use java’s string functions to extract the relevant data but is this possible using a parser or even xpath? or do they both expect the xml document to be a well formed document before it can parse it?

  • 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-24T10:29:13+00:00Added an answer on May 24, 2026 at 10:29 am

    You could try to use JSoup to parse the invalid XML. By definition XML should be well-formed, otherwise it’s invalid and should not be used.

    UPDATE – example:

    public static void main(String[] args) {
        for (Node node : Parser.parseFragment("<test><author name=\"Vlad\"><book name=\"SO\"/>" ,
                new Element(Tag.valueOf("p"), ""),
                "")) {
            print(node, 0);
        }
    }
    
    public static void print(Node node, int offset) {
        for (int i = 0; i < offset; i++) {
            System.out.print(" ");
        }
        System.out.print(node.nodeName());
        for (Attribute attribute: node.attributes()) {
            System.out.print(", ");
            System.out.print(attribute.getKey() + "=" + attribute.getValue());
        }
        System.out.println();
        for (Node child : node.childNodes()) {
            print(child, offset + 4);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that fetches info from other pages and parses them using
I am attempting to parse a XML file using Javascript and I'm running into
I have an XmlTextWriter writing to a file and an XmlWriter using that text
I've been using resx files for static strings in order to have a central
I have a file, which is in XML format (consists just of root start
I need to parse and process an XML feed, unfortunately the feed is about
I'd like to read a large XML file that contains over a million small
Hi I'm looking to parse spreadsheets (xls/ods) in Groovy. I have been using the
I have a problem with a SAX xml parser. I want to parse a
Right now i have a batch job I wrote that calls another file and

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.