Iterator iter= jarPackage.getSelectedElements().iterator();
Iterator iter= jarPackage.getSelectedElementsClosure();
    public void writeXML(JarPackage jarPackage) throws IOException {    	Assert.isNotNull(jarPackage);    	DocumentBuilder docBuilder= null;    	DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();    	factory.setValidating(true); 		try {   		    	docBuilder= factory.newDocumentBuilder();		} catch (ParserConfigurationException ex) {			throw new IOException(JarPackagerMessages.getString("JarWriter.error.couldNotGetXmlBuilder")); //$NON-NLS-1$ 		}		Document document= docBuilder.newDocument();				// Document and root node		Element xmlJarDesc= document.createElement(JarPackage.DESCRIPTION_EXTENSION);		document.appendChild(xmlJarDesc);		// JAR location		Element jar= document.createElement(JarPackage.EXTENSION);		xmlJarDesc.appendChild(jar);		jar.setAttribute("path", jarPackage.getJarLocation().toString()); //$NON-NLS-1$				// Options		Element options= document.createElement("options"); //$NON-NLS-1$		xmlJarDesc.appendChild(options);		options.setAttribute("overwrite", "" + jarPackage.allowOverwrite()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("compress", "" + jarPackage.isCompressed()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("exportErrors", "" + jarPackage.exportWarnings()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("exportWarnings", "" + jarPackage.exportWarnings()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("logErrors", "" + jarPackage.logErrors()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("logWarnings", "" + jarPackage.logWarnings()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("saveDescription", "" + jarPackage.isDescriptionSaved()); //$NON-NLS-2$ //$NON-NLS-1$		options.setAttribute("descriptionLocation", jarPackage.getDescriptionLocation().toString()); //$NON-NLS-1$		// Manifest		Element manifest= document.createElement("manifest"); //$NON-NLS-1$		xmlJarDesc.appendChild(manifest);		manifest.setAttribute("manifestVersion", jarPackage.getManifestVersion()); //$NON-NLS-1$		manifest.setAttribute("usesManifest", "" + jarPackage.usesManifest()); //$NON-NLS-2$ //$NON-NLS-1$		manifest.setAttribute("reuseManifest", "" + jarPackage.isManifestReused()); //$NON-NLS-2$ //$NON-NLS-1$		manifest.setAttribute("saveManifest", "" + jarPackage.isManifestSaved()); //$NON-NLS-2$ //$NON-NLS-1$		manifest.setAttribute("generateManifest", "" + jarPackage.isManifestGenerated()); //$NON-NLS-2$ //$NON-NLS-1$		manifest.setAttribute("manifestLocation", jarPackage.getManifestLocation().toString()); //$NON-NLS-1$		if (jarPackage.getMainClass() != null)			manifest.setAttribute("mainClassHandleIdentifier", jarPackage.getMainClass().getHandleIdentifier()); //$NON-NLS-1$		// Sealing		Element sealing= document.createElement("sealing"); //$NON-NLS-1$		manifest.appendChild(sealing);		sealing.setAttribute("sealJar", "" + jarPackage.isJarSealed()); //$NON-NLS-2$ //$NON-NLS-1$		Element packagesToSeal= document.createElement("packagesToSeal"); //$NON-NLS-1$		sealing.appendChild(packagesToSeal);		add(jarPackage.getPackagesToSeal(), packagesToSeal, document);		Element packagesToUnSeal= document.createElement("packagesToUnSeal"); //$NON-NLS-1$		sealing.appendChild(packagesToUnSeal);		add(jarPackage.getPackagesToUnseal(), packagesToUnSeal, document);		// Selected elements		Element selectedElements= document.createElement("selectedElements"); //$NON-NLS-1$		xmlJarDesc.appendChild(selectedElements);		selectedElements.setAttribute("exportClassFiles", "" + jarPackage.areClassFilesExported()); //$NON-NLS-2$ //$NON-NLS-1$		selectedElements.setAttribute("exportJavaFiles", "" + jarPackage.areJavaFilesExported()); //$NON-NLS-2$ //$NON-NLS-1$		Iterator iter= jarPackage.getSelectedElements().iterator();		while (iter.hasNext()) {			Object element= iter.next();			if (element instanceof IResource)				add((IResource)element, selectedElements, document);			else if (element instanceof IJavaElement)				add((IJavaElement)element, selectedElements, document);			// Note: Other file types are not handled by this writer		}		// Write the document to the stream		OutputFormat format= new OutputFormat();		format.setIndenting(true);		SerializerFactory serializerFactory= SerializerFactory.getSerializerFactory(Method.XML);		Serializer serializer= serializerFactory.makeSerializer(fOutputStream,	format);		serializer.asDOMSerializer().serialize(document);    }