public void loadFile(String pathname, String filename) { try { // Build & creat the document with SAX, use XML schema validation URL path = ClassLoader.getSystemResource("ANNeML.xsd"); if(path.getFile()==null) { jLabel2.setForeground(Color.RED); jLabel2.setText("error loading XML schema"); } else{ //File argylexsd = new File(path.toURI()); //XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(argylexsd); XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory("ANNeML.xsd"); //***for .jar deployment SAXBuilder builder = new SAXBuilder(schemafac); AL_gui.NNetMap = builder.build(pathname); java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(AL_gui.NNetMap); java.util.List layers = XPath.newInstance("//LAYER").selectNodes(AL_gui.NNetMap); java.util.List inputNeurodes = XPath.newInstance("//NEURODE[SYNAPSE/@ORG_NEURODE='INPUT']").selectNodes(AL_gui.NNetMap); java.util.List hiddenNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='HIDDEN']/NEURODE").selectNodes(AL_gui.NNetMap); java.util.List outputNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='OUTPUT']/NEURODE").selectNodes(AL_gui.NNetMap); jLabel2.setForeground(Color.GREEN); jLabel2.setText("Valid ANNeML file."); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(AL_gui.this, "There was an error parsing the file.\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } }
/** * Parses the PhyloXML file and fill the structure of MetaML. * * @param f PhyloXML file. * @return Returns an PhyloXML object. */ private PhyloXML readPhyloXML(File f) throws JDOMException { try { // TODO A round of non-validating parsing to get the file name of the referenced XSD // Set the implementation of SAXParserFactory to the one bundled wit the JRE System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); // Read bundled XML schema URL xsdUrl = getClass().getResource("/schemas/phyloxml-1.10.xsd"); XMLReaderJDOMFactory factory = new XMLReaderXSDFactory(xsdUrl); // This builder validates against the provided XSD SAXBuilder sb = new SAXBuilder(factory); Document doc = sb.build(f); Element rootElement = doc.getRootElement(); Namespace phyloXMLNamespace = rootElement.getNamespace(); /* * Parse <phyloxml> */ Namespace defaultNamespace = Namespace.getNamespace("phyloxml", phyloXMLNamespace.getURI()); XPathExpression<Element> phylogenyExpression = xpfac.compile("phyloxml:"+Constants.PHYLOXML_PHYLOGENY, Filters.element(), null, defaultNamespace); for (Element phylogenyElement : phylogenyExpression.evaluate(rootElement)) { Phylogeny phylogeny = new Phylogeny(this); readSubClades(defaultNamespace, phylogeny, phylogenyElement, null); /* * This is a pretty dirty hack. We just hijack the * phylogenyObject2 field, knowing that readSubClades will * add the Clades to this Phylogeny. After one phylogeny has * been processed we add phylogenyObject2 to the list of * phylogenies and start over again. * * THIS HACK WILL NOT BE THREADSAFE!! */ phylogenies.add(phylogeny); } /* * Parse project name */ Namespace metaXMLNamespace = Namespace.getNamespace("metaxml", "http://metaXML.fz-juelich.de"); XPathExpression<Element> projectNameExpression = xpfac.compile("metaxml:"+Constants.PHYLOXML_PROJECTNAME, Filters.element(), null, metaXMLNamespace); for (Element projectNameElement : projectNameExpression.evaluate(rootElement)) { this.projectName = projectNameElement.getValue(); } } catch (IOException ex) { /* TODO Handle exceptions properly */ logger.error("Loading from file failed", ex); } return new PhyloXML(phylogenies); }