use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class XMLDict method main.
// tests the x-path functionality
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
if (args.length < 1)
System.out.println("Test Usage: XMLDict test_BioModel_File");
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new FileReader(args[0]));
Element root = doc.getRootElement();
// not the actual usage, but works for testing
XMLDict dict = new XMLDict();
// add just one round
dict.put(root, root.getClass().getName() + ":" + root.getAttributeValue(XMLTags.NameTag), root);
Iterator<Element> i = root.getChildren().iterator();
while (i.hasNext()) {
Element temp = i.next();
dict.put(temp, temp.getClass().getName() + ":" + temp.getAttributeValue(XMLTags.NameTag), temp);
}
Enumeration<String> e = dict.keys();
while (e.hasMoreElements()) {
String key = e.nextElement();
Object value = dict.get(key);
System.out.println("key: " + key + " value: " + value);
}
i = root.getChildren().iterator();
while (i.hasNext()) {
Element temp = (Element) i.next();
Element value = (Element) dict.get(temp, temp.getClass().getName() + ":" + temp.getAttributeValue(XMLTags.NameTag));
System.out.println(value.getName() + " " + value.getAttributeValue(XMLTags.NameTag) + " " + temp.getName() + " " + temp.getAttributeValue(XMLTags.NameTag));
}
}
use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class SEDMLReader method readFile.
public static SedML readFile(File file) throws JDOMException, IOException, XMLException {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(file);
Element sedRoot = doc.getRootElement();
try {
SEDMLElementFactory.getInstance().setStrictCreation(false);
SEDMLReader reader = new SEDMLReader();
SedML sedML = reader.getSedDocument(sedRoot);
return sedML;
} finally {
SEDMLElementFactory.getInstance().setStrictCreation(true);
}
}
use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class SEDMLUtils method readSedDocument.
/**
* Reads in a SEDML (XML) file into a SedDocument
* @param fileName
* @return
*/
static SedML readSedDocument(String fileName) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(fileName));
Element sedRoot = doc.getRootElement();
SEDMLReader reader = new SEDMLReader();
SedML sedDoc = reader.getSedDocument(sedRoot);
return sedDoc;
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Could not create SedMLDocument from file '" + fileName + "'");
}
}
use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class Libsedml method createDocument.
private static Document createDocument(InputStream in) throws XMLException {
SAXBuilder builder = new SAXBuilder();
Document doc;
try {
doc = builder.build(in);
} catch (JDOMException e) {
throw new XMLException("Error reading file", e);
} catch (IOException e) {
throw new XMLException("Error reading file", e);
}
return doc;
}
use of org.jdom.input.SAXBuilder in project yamcs-studio by yamcs.
the class FileUtil method loadXMLFile.
/**
* Load the root element of an XML file. The element is a JDOM Element.
*
* @param filePath
* path of the file. It can be an absolute path or a relative path to the OPI that contains the specified
* widget. If it is an absolute path, it can be either<br>
* a workspace path such as <code>/OPI Examples/Scripts/myfile.xml</code><br>
* a local file system path such as <code>C:\myfile.xml</code><br>
* or an URL path such as <code>http://mysite.com/myfile.xml</code>.
* @param widget
* a widget in the OPI, which is used to provide relative path reference. It can be null if the path is
* an absolute path.
* @return root element of the XML file.
* @throws Exception
* if the file does not exist or is not a correct XML file.
*/
public static Element loadXMLFile(String filePath, AbstractBaseEditPart widget) throws Exception {
var path = buildAbsolutePath(filePath, widget);
var saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver(new CssEntityResolver());
var file = ResourceUtil.getFile(path);
Document doc;
if (file == null) {
var inputStream = ResourceUtil.pathToInputStream(path);
doc = saxBuilder.build(inputStream);
inputStream.close();
} else {
doc = saxBuilder.build(file);
}
return doc.getRootElement();
}
Aggregations