use of org.jaxen.xom.XOMXPath in project vcell by virtualcell.
the class SEDMLUtils method parseXPath.
/**
* Parses xPath string specified as arg1 in XML file specified as arg2 (using XOM and Jaxen)
* @param xPathExpr
* @param xmlFile
* @return
*/
private static String parseXPath(String xPathExpr, File xmlFile) {
try {
Builder builder = new Builder();
nu.xom.Document document = builder.build(xmlFile);
nu.xom.Element rootElement = document.getRootElement();
String defaultNamespaceURI = rootElement.getNamespaceURI();
String defaultNamespacePrefix = rootElement.getNamespacePrefix();
if ("".equals(defaultNamespacePrefix)) {
ToolSupport.nameSpaces_PrefixesHashMap.put("sbml", defaultNamespaceURI);
} else {
ToolSupport.nameSpaces_PrefixesHashMap.put(defaultNamespacePrefix, defaultNamespaceURI);
}
org.jaxen.XPath xpath = new XOMXPath(xPathExpr);
xpath.setNamespaceContext(new SimpleNamespaceContext(ToolSupport.nameSpaces_PrefixesHashMap));
Object node = xpath.selectSingleNode(document);
String elementId = ((nu.xom.Element) node).getAttributeValue("id");
log.debug("Returned node id : " + elementId);
return elementId;
} catch (JaxenException e) {
// An error occurred parsing or executing the XPath
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (IOException e) {
// An error occurred opening the document
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (ParsingException e) {
// An error occurred parsing the document
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
Aggregations