New release of NanoXML (v2.2.5) to Allow Manual Release of File Resource
Join the DZone community and get the full member experience.Join For Free
important: this version is not the official release by the original author of nanoxml ( http://nanoxml.cyberelf.be/ ). it appears that the development for nanoxml has ceased.
editors notes: reposted on behalf of http://geekycoder.wordpress.com
issue in nanoxml
back in 2008, a version of nanoxml v2.2.4 is “unofficial” released to add comment feature ( javalobby mirror ). however, there is one problem that persists which prevent developers from using nanoxml to manipulate xml file. the developers might use xml file for to store profile for their application and will need to manage xml file (etc delete, rename, add). however, it turns out that nanoxml is locking the xml file while waiting for the garbage collector to kick in and release the file. however the gc is behaving unpredictably and might not release the file as and when the program expects it. the developers will thus want more control over the release of file resource. unfortunately, there is currently no api to force release of file resource under current release.
therefore, i have modified nanoxml and released it as nanoxml v2.2.5 to allow developers to use a specific method to release file resource manually so that the file can be manipulated (etc delete, rename).
public void dispose()
this will release all file resource that are held up by reader.
the aforementioned method will release the file resource that is created using the static method ixmlreader filereader(string filename) in stdxmlreader class.
public class xmltest
// ## means new features added.
public static void main(string _args) throws exception
ixmlparser parser = xmlparserfactory.createdefaultxmlparser();
/*// if pass string, use stringreader
ixmlreader reader = stdxmlreader.stringreader(“<root></root>”);
// pass by file. important to use tourl method otherwise exception will be thrown.
ixmlreader reader = stdxmlreader.filereader(
// parse() method does not include comment
ixmlelement xml = (ixmlelement) parser.parse(true); // ## true means parse comment too
ixmlelement _x = xml.createelement(“newchild”);
_x.setcomment(“this is new child”); // ## adding comment
xml.addchild(_x, 0); // ## adding at specific position.
ixmlelement _b = xml.getchildatindex(1);
xml.removechild(_b); // remove tag
xmlwriter writer = new xmlwriter(system.out);
// default for write is excluded comment
writer.setincludecomment(true); // ## include comment at generation.
download nanoxml v2.2.5
the following file contains the full source code and the library jar file. to check on those changes that i have made, you can search for ‘ geekycoder ’ in the source code.
Opinions expressed by DZone contributors are their own.