return output;
}
private Document createXml(File file) throws FitsToolException {
Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
Namespace fitsNS = Namespace.getNamespace(Fits.XML_NAMESPACE);
Element root = new Element("fits",fitsNS);
root.setAttribute(new Attribute("schemaLocation","http://hul.harvard.edu/ois/xml/ns/fits/fits_output "+Fits.externalOutputSchema,xsiNS));
//If the file is XML then parse and set text metadata
if(file.getPath().toLowerCase().endsWith(".xml")) {
Element metadata = new Element("metadata",fitsNS);
Element textMetadata = new Element("text",fitsNS);
Document xml = null;
try {
saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",false);
saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
xml = saxBuilder.build(file);
} catch (Exception e) {
throw new FitsToolException("Error parsing "+file.getPath(),e);
}
if(xml != null) {
//assume we have at least well formed XML
Element identification = new Element("identification",fitsNS);
Element identity = new Element("identity",fitsNS);
identity.setAttribute("format",XML_FORMAT);
identity.setAttribute("mimetype",XML_MIME);
//add identity to identification section
identification.addContent(identity);
//add identification section to root
root.addContent(identification);
Element xmlRoot = xml.getRootElement();
String defaultNamespaceURI = xmlRoot.getNamespaceURI();
List<Namespace> namespaces = xmlRoot.getAdditionalNamespaces();
String schemaPrefix = null;
for(Namespace n : namespaces) {
if(n.getURI().equalsIgnoreCase(XML_SCHEMA_INSTANCE)) {
schemaPrefix = n.getPrefix();
break;
}
}
Namespace schemaNS = xmlRoot.getNamespace(schemaPrefix);
String schemaLocations = null;
String noNamespaceSchemaLocation = null;
if(schemaNS != null) {
schemaLocations = xmlRoot.getAttributeValue("schemaLocation",schemaNS);
noNamespaceSchemaLocation = xmlRoot.getAttributeValue("noNamespaceSchemaLocation",schemaNS);