XPath xpath = XPath.newInstance("//fits:identity");
Namespace ns = Namespace.getNamespace("fits",Fits.XML_NAMESPACE);
xpath.addNamespace(ns);
List<Element> identElements = xpath.selectNodes(fitsXml);
for(Element element : identElements) {
FitsIdentity fileIdentSect = new FitsIdentity();
//get the identity attributes
Attribute formatAttr = element.getAttribute("format");
Attribute mimetypeAttr = element.getAttribute("mimetype");
if(formatAttr != null) {
fileIdentSect.setFormat(formatAttr.getValue());
}
if(mimetypeAttr != null) {
fileIdentSect.setMimetype(mimetypeAttr.getValue());
}
//get the tool elements
List<Element> toolElements = element.getChildren("tool",ns);
for(Element toolElement : toolElements) {
ToolInfo toolInfo = new ToolInfo();
Attribute toolNameAttr = toolElement.getAttribute("toolname");
Attribute toolVersionAttr = toolElement.getAttribute("toolversion");
if(toolNameAttr != null) {
toolInfo.setName(toolNameAttr.getValue());
}
if(toolVersionAttr != null) {
toolInfo.setVersion(toolVersionAttr.getValue());
}
fileIdentSect.addReportingTool(toolInfo);
}
//get the version elements
List<Element> versionElements = element.getChildren("version",ns);
for(Element versionElement : versionElements) {
ToolInfo toolInfo = new ToolInfo();
Attribute toolNameAttr = versionElement.getAttribute("toolname");
Attribute toolVersionAttr = versionElement.getAttribute("toolversion");
if(toolNameAttr != null) {
toolInfo.setName(toolNameAttr.getValue());
}
if(toolVersionAttr != null) {
toolInfo.setVersion(toolVersionAttr.getValue());
}
String value = versionElement.getText();
FormatVersion formatVersion = new FormatVersion(value,toolInfo);
fileIdentSect.addFormatVersion(formatVersion);
}
//get the externalIdentifier elements
List<Element> xIDElements = element.getChildren("externalIdentifier",ns);
for(Element xIDElement : xIDElements) {
String type = xIDElement.getAttributeValue("type");
String value = xIDElement.getText();
ToolInfo toolInfo = new ToolInfo();
Attribute toolNameAttr = xIDElement.getAttribute("toolname");
Attribute toolVersionAttr = xIDElement.getAttribute("toolversion");
if(toolNameAttr != null) {
toolInfo.setName(toolNameAttr.getValue());
}
if(toolVersionAttr != null) {
toolInfo.setVersion(toolVersionAttr.getValue());
}
ExternalIdentifier xid = new ExternalIdentifier(type,value,toolInfo);
fileIdentSect.addExternalID(xid);
}
identities.add(fileIdentSect);
}
} catch (JDOMException e) {
e.printStackTrace();