public boolean processXML(File file,Document doc,boolean forceRefresh) throws Exception {
        Element root=doc.getDocumentElement();
        List<FragmentDirective> fragments=new ArrayList<FragmentDirective>();
        scanComments(root,fragments);

        MessageDigest digest=MessageDigest.getInstance("SHA-1");

        boolean modified=false;
        for(FragmentDirective frag:fragments) {
            DocumentFragment fragmentDoc=loadFragment(frag.fileName);
            digest.reset();
            digestFragment(digest,fragmentDoc);
            String hash=tostr(digest.digest());
            if(frag instanceof FragmentContent) {
                FragmentContent fc=(FragmentContent)frag;
                // Check if the fragment needs to be replaced
                // First compute the real hash of the fragment
                digest.reset();
                digest(digest,fc.nodes);
                String fragmentHash=tostr(digest.digest());
                if(fragmentHash.equals(fc.hash)||forceRefresh) {
                    // Fragment was not modified, so we can replace it
                    if(!fragmentHash.equals(hash)||forceRefresh) {
                        // The replacement content is modified. We need to replace
                        // Remove all nodes except the first and last
                        int n=fc.nodes.size();
                        Node lastNode=fc.nodes.get(n-1);
                        int i=0;
                        for(Node node:fc.nodes) {
                            if(i>0&&node!=lastNode) {
                                node.getParentNode().removeChild(node);
                            }
                            i++;
                        }
                        // Insert the fragment after the first comment node
                        importFragment(fc.nodes.get(n-1),fragmentDoc,doc);
                        // Modify the comment node text to reflect the new hash
                        ((Comment)fc.nodes.get(0)).setData("Fragment Begin: "+fc.fileName+" "+hash);
                        modified=true;
                    } 
                } else
                    System.out.println(file.toString()+": Fragment for "+frag.fileName+
                                       " was modified in file, cannot replace (fragment file hash:"+hash+" hash in file:"+fragmentHash+" has in comment:"+fc.hash+")");
            } else {
                // This will be the fragment end comment node
                frag.node.setData("Fragment End: "+frag.fileName);
                Comment c=doc.createComment("Fragment Begin: "+frag.fileName+" "+hash);
                frag.node.getParentNode().insertBefore(c,frag.node);
                // Import the fragment here
                importFragment(frag.node,fragmentDoc,doc);
                modified=true;
            }
        }
        return modified;
    }