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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:52:27+00:00 2026-06-13T12:52:27+00:00

I am using VTD-XML to split a large xml file into smaller xml files.

  • 0

I am using VTD-XML to split a large xml file into smaller xml files. Everything works great accept the:

autoPilot.selectXPath("//nodeName")

It is skipping over the first 3 nodes for some reason.

EDIT: vtd-xml-author pointed out that LOG.info("xpath has found "+ ap.evalXPath() +" items"); does not return the count but returns the node index.

The new split xml file is missing the first three nodes from the original file.

Here is basic XML layout. I can’t display the true xml data but here is what it looks like:

<rootNode>
          <parentNode>
                      <contentNode>..children inside...</contentNode>
                      <contentNode>..children inside...</contentNode>
                      <contentNode>..children inside...</contentNode>
                      <contentNode>..children inside...</contentNode>
          </parentNode>
</rootNode>

And here is the function i am using to split the xml:

public void splitXml(String parentNode, String contentNodes)throws Exception {
    LOG.info("Splitting " + outputName + parentNode);
    VTDGen vg = new VTDGen();   

     if (vg.parseFile(xmlSource, true)){

        VTDNav vn = vg.getNav();
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("//"+contentNode);

        int i=-1;
        int k=0;
        byte[] ba = vn.getXML().getBytes();
        FileOutputStream fos = getNewXml(parentNode);
        while((i=ap.evalXPath())!=-1){

            if(fos.getChannel().size() > maxFileSize){
                finishXml(fos,contentNode);
                LOG.info("Finished file with " + k + "nodes");
                fos = getNewXml(contentNode);
                k=0;
            }
            k++;
            long l = vn.getElementFragment();
            fos.write(ba, (int)l, (int)(l>>32));
            fos.write("\n".getBytes());
        }
        finishXml(fos,contentNode);
        LOG.info("Finished Splitting " + outputName + " " + parentNode + " with " +k+ " nodes");
    } else {
        LOG.info("Parse Failed");
    }


}

Edit: added in counter to while loop.

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

    as vtd-xml-author suggested i added in the counter to the while loop.

            while((i=ap.evalXPath())!=-1){
                // if filesize is at max create a new File
                if(fos.getChannel().size() > maxFileSize){
                    finishXml(fos,contentNode);
                    LOG.info("Finished file with " + k + "nodes");
                    fos = getNewXml(contentNode);
                    k=0;
    
                }
                k++;
                long l = vn.getElementFragment();
                fos.write(ba, (int)l, (int)(l>>32));
                fos.write("\n".getBytes());
            }
    

    The first time i ran it the output was only missing 1 record. I then deleted the output xml files and the folder and re-ran it the splitter. This time it came back with the correct number in the log and correctly split the files. I repeated the process numerous times while deleting the created folder and files and also without deleting the files. I got the same correct results every time. I am guessing that the IDE or something wasn’t refreshing correctly.

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

Sidebar

Related Questions

I'm using VTD-XML to parse some XML files with Xpath expressions, now following showed
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
I am using VTD-XML 2.10 in Java. I have problem on how to select
Using Java,I have to fetch multiple sets of values from an XML file to
Using C#.NET, i wrote a toolbar which is stored now into toolbar.cs file. I
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using mercurial, I've run into an odd problem where a line from one committer
Using the HTML5 File API I can get the Binary String representation of a
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,
Using TortoiseSVN against VisualSVN I delete a source file that I should not have

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.