Archive for January 31st, 2010

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.

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.

NanoXML v2.2.5

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 close()
    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(
                new File(“c:/test.xml”).toURI().getPath());

        // 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
        _x.setAttribute(“att1″, “me1″);
        _x.setAttribute(“att2″, “me2″);
        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.
        writer.write(xml, true);





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.

NanoXML-2.2.5.zip (93kb)

Released on 6 Feb 2010


Read Full Post »