use of org.jdom2.input.SAXBuilder in project opentheso by miledrousset.
the class testimportxml method ouvreFichier.
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void ouvreFichier() {
HikariDataSource conn = openConnexionPool();
SAXBuilder builder = new SAXBuilder();
ArrayList<Table> toutTables = new ArrayList<>();
ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
File xmlFile = new File("C:/Users/antonio.perez/Desktop/testbon.xml");
try {
// Se crea el documento a traves del archivo
Document document = (Document) builder.build(xmlFile);
// Se obtiene la raiz 'tables'
Element rootNode = document.getRootElement();
// Se obtiene la lista de hijos de la raiz 'tables'
// ici on a toutes les tables (les enfants de la racine)
List list = rootNode.getChildren("table");
// Se recorre la lista de hijos de 'tables'
for (int i = 0; i < list.size(); i++) {
// Se obtiene el elemento 'tabla'
// ici on a la première table
Element tabla = (Element) list.get(i);
// Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
// ici on a le nom de la table
String nombreTabla = tabla.getAttributeValue("nom");
System.out.println("Nom de la table : " + nombreTabla);
// Se obtiene la lista de hijos del tag 'tabla'
// ici c'est la liste des lignes de la table
List lista_campos = tabla.getChildren();
// ici on découpe la liste des lignes
for (int j = 0; j < lista_campos.size(); j++) {
// Se obtiene el elemento 'campo'
// ici on a une ligne de la table
Element campo = (Element) lista_campos.get(j);
// System.out.println("nouvelle ligne table "+ nombreTabla);
for (Element colonne : campo.getChildren()) {
LineOfData lineOfData = new LineOfData();
// System.out.println("Nom de la colonne = " + colonne.getName());
// System.out.println("valeur de la colonne = " + colonne.getText());
lineOfData.setColomne(colonne.getName());
lineOfData.setValue(colonne.getText());
lineOfDatas.add(lineOfData);
}
insertLine(conn, lineOfDatas, nombreTabla);
lineOfDatas.clear();
}
// / mettre à jour la table dans la BDD
}
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
}
use of org.jdom2.input.SAXBuilder in project k-9 by k9mail.
the class SettingsExporterTest method parseXML.
private Document parseXML(byte[] xml) throws Exception {
SAXBuilder builder = new SAXBuilder();
InputStream stream = new ByteArrayInputStream(xml);
return builder.build(stream);
}
use of org.jdom2.input.SAXBuilder in project pcgen by PCGen.
the class Initiative method loadINIT.
/**
* Perform initial loading
* @param initFile
* @param comp
*/
public void loadINIT(File initFile, PCGenMessageHandler comp) {
try {
SAXBuilder builder = new SAXBuilder();
Document character = builder.build(initFile);
loadFromDocument(character, comp);
} catch (Exception e) {
JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(this), "File load error: " + initFile.getName());
Logging.errorPrint("File Load Error" + initFile.getName());
Logging.errorPrint(e.getMessage(), e);
}
}
use of org.jdom2.input.SAXBuilder in project JMRI by JMRI.
the class XmlFile method getBuilder.
public static SAXBuilder getBuilder(Validate validate) {
// should really be a Verify enum
SAXBuilder builder;
boolean verifyDTD = (validate == Validate.CheckDtd) || (validate == Validate.CheckDtdThenSchema);
boolean verifySchema = (validate == Validate.RequireSchema) || (validate == Validate.CheckDtdThenSchema);
// old style
// argument controls DTD validation
builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", verifyDTD);
// insert local resolver for includes, schema, DTDs
builder.setEntityResolver(new JmriLocalEntityResolver());
// configure XInclude handling
builder.setFeature("http://apache.org/xml/features/xinclude", true);
builder.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
// only validate if grammar is available, making ABSENT OK
builder.setFeature("http://apache.org/xml/features/validation/dynamic", verifyDTD && !verifySchema);
// control Schema validation
builder.setFeature("http://apache.org/xml/features/validation/schema", verifySchema);
builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", verifySchema);
// if not validating DTD, just validate Schema
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", verifyDTD);
if (!verifyDTD) {
builder.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
}
// allow Java character encodings
builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
return builder;
}
use of org.jdom2.input.SAXBuilder in project JMRI by JMRI.
the class XmlFileTest method testProcessPI.
public void testProcessPI() throws org.jdom2.JDOMException, java.io.IOException {
// Document from test file
Document doc;
Element e;
FileInputStream fs = new FileInputStream(new File("java/test/jmri/jmrit/XmlFileTest_PI.xml"));
try {
// argument controls validation
SAXBuilder builder = XmlFile.getBuilder(XmlFile.Validate.None);
doc = builder.build(new BufferedInputStream(fs));
Assert.assertNotNull("Original Document found", doc);
e = doc.getRootElement();
Assert.assertNotNull("Original root element found", e);
XmlFile x = new XmlFile() {
};
Document d = x.processInstructions(doc);
Assert.assertNotNull(d);
// test transform changes <contains> element to <content>
e = d.getRootElement();
Assert.assertNotNull("Transformed root element found", e);
Assert.assertTrue("Transformed root element is right type", e.getName().equals("top"));
Assert.assertTrue("Old element gone", e.getChild("contains") == null);
Assert.assertTrue("New element there", e.getChild("content") != null);
Assert.assertTrue("New element has content", e.getChild("content").getChildren().size() == 2);
} catch (java.io.IOException ex) {
throw ex;
} catch (org.jdom2.JDOMException ex) {
throw ex;
} finally {
fs.close();
}
}
Aggregations