aspose file tools*
The moose likes XML and Related Technologies and the fly likes xmlbeans caching document during parse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xmlbeans caching document during parse?" Watch "xmlbeans caching document during parse?" New topic
Author

xmlbeans caching document during parse?

Andy Westley
Greenhorn

Joined: Nov 09, 2004
Posts: 19
Hi there,

I've posted this in the xml forum, because I'm having trouble with some xml/xmlbeans, but I'm not convinced it's not a classloader issue.

I'm using an xml file as a simple data store for a web app I'm writing. I'm deploying the webapp including a default xml file for start up, but add, edit and delete operations throught we webapp will be modifying the xml file that gets exploded out of the .war file.

For neatness I've been using the code

MyUtitlityClass.class.getResourceAsStream("/my_data_file.xml")

to load the file from what I thought would be the file system. As you might be able to detect I've been having problems where, saving the file updates the file on the file system (I can see it update in my IDE), but the next time I load the file, my updates don't appear. I'm wondering whether getResourceAsStream is returning me a reference to the file in the .war, rather than the exploded and updated one on the filesystem.

The only thing that makes me think otherwise, is that if I restart tomcat, the application loads the updated version of the file. It's like the reference to the file is cached - obviously without me intending it to be.

Does anyone recognise the symptoms? Can anyone suggest any approaches for identifying whether the problem is in the loading or in the parsing?

Cheers
aw
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

To start with you could use the "getResource()" method to return you a URL. That would at least answer your question about just where the resource is being loaded from.
Andy Westley
Greenhorn

Joined: Nov 09, 2004
Posts: 19
Thanks Paul, that was a good tip. Unfortunately, it threw my theory out the window. Checking the URL in the way you suggested proves that I'm parsing the updated file from the filesystem everytime I access it.

That leaves the question of why the

XDocument.Factory.parse(myInputStream)

call doesn't seem to get the up-to-date contents of the file.

I've got a work around, but it's a bit that it doesn't work as expected.

Cheers
aw
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I don't know, if you were passing a URL to the parse() method I could see the possibility that it was caching the XML it read from that URL. (In some places, like for example in XSLT's document() function, it's actually mandatory for software to cache XML.) But caching the contents read from an InputStream seems more improbable to me. However I don't know much about XMLBeans, maybe you're doing something that requires caching.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xmlbeans caching document during parse?