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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:43:36+00:00 2026-05-24T07:43:36+00:00

We are validating XML files and depending on the result of the validation we

  • 0

We are validating XML files and depending on the result of the validation we have to move the file into a different folder.

When the XML is valid the validator returns a value and we can move the file without a problem. Same thing happens when the XML is not valid according to the schema.

If however the XML is not well formed the validator throws an exception and when we try to move the file, it fails. We believe there is still a handle in the memory somewhere that keeps hold of the file. We tried putting System.gc() before moving the file and that sorted the problem but we can’t have System.gc() as a solution.

The code looks like this. We have a File object from which we create a StreamSource. The StreamSource is then passed to the validator. When the XML is not well formed it throws a SAXException. In the exception handling we use the .renameTo() method to move the file.

sc = new StreamSource(xmlFile);
validator.validate(sc);

In the catch we tried

validator.reset();
validator=null;
sc=null;

but still .renameTo() is not able to move the file. If we put System.gc() in the catch, the move will succeed.

Can someone enlight me how to sort this without System.gc()?

We use JAXP and saxon-9.1.0.8 as the parser.

Many thanks

  • 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-24T07:43:36+00:00Added an answer on May 24, 2026 at 7:43 am

    Try creating a FileInputStream and passing that into StreamSource then close the FileInputStream when you’re done. By passing in a File you have lost control of how/when to close the file handle.

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

Sidebar

Related Questions

I have looked at many examples for validating an XML file against a DTD,
I have problems with validating the xml file against xml schema in case when
I have a C# Web Service that returns a XML as a result that
Here is my first attempt at validating XML with XSD. The XML file to
I'm new to XML validation using .xsd files. Maybe I'm not even asking the
When Excel saves a file, it attempts to combine identical Validation settings into a
I have a piece of xml that contains optional non-enumerated elements, so schema validation
We have a source XML file that has an address node, and each node
Validating an XML file in Haskell works fine with HXT and Relax NG ,
I have an XML file that I'm trying to validate against an XSD file

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.