Example usage for org.jdom2.input SAXBuilder build

List of usage examples for org.jdom2.input SAXBuilder build

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder build.

Prototype

@Override
public Document build(final String systemId) throws JDOMException, IOException 

Source Link

Document

This builds a document from the supplied URI.

Usage

From source file:edd.practica1_201504480.leerxml.java

Lista_Simple datos(File tipo1) {

    SAXBuilder builder = new SAXBuilder();
    try {//from w  ww.  ja v a 2 s  . co  m

        //Se obtiene la lista de hijos de la raiz 'tables'
        Document document = builder.build(tipo1);
        Element rootNode = document.getRootElement();
        //  JOptionPane.showMessageDialog(null," e1: "+(rootNode.getChildText("dimension"))); 
        tam = Integer.parseInt(rootNode.getChildText("dimension"));
        Element dobles = rootNode.getChild("dobles");

        List list = dobles.getChildren("casilla");
        for (int i = 0; i < list.size(); i++) {
            Element tabla = (Element) list.get(i);
            d1.enlistar(tabla.getChildTextTrim("x"));

            d1.enlistar(tabla.getChildTextTrim("y"));
            //              JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("x").toString());
            //                JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("y").toString());
        }

        Element triples = rootNode.getChild("triples");

        List listt = triples.getChildren("casilla");
        for (int i = 0; i < listt.size(); i++) {
            Element tabla = (Element) listt.get(i);
            d2.enlistar(tabla.getChildTextTrim("x"));
            d2.enlistar(tabla.getChildTextTrim("y"));
            //              JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("x").toString());
            //                JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("y").toString());
        }
        Element dicc = rootNode.getChild("diccionario");
        List dic = dicc.getChildren();

        for (int i = 0; i < dic.size(); i++) {
            Element tabla = (Element) dic.get(i);
            //JOptionPane.showMessageDialog(null,""+tabla.getText().toString());
            d.enlistar(tabla.getText().toString());

        }

    } catch (JDOMException | IOException | NumberFormatException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " error de archivo");
    }
    return d;

}

From source file:eddpractica1_201503692.CargaXML.java

public void cargarXml(File xml) {
    //Parseo Arhchivo

    SAXBuilder builder = new SAXBuilder();

    try {//w  ww  .ja v a 2s.  c  o  m
        //Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xml);
        List elemento = document.getContent();

        //Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();

        //Se obtiene la lista de hijos de la raiz 'tables'
        List list = rootNode.getChildren("diccionario");
        List list1 = rootNode.getChildren("dobles");

        //Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list.get(i);

            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            String nombreTabla = tabla.getValue();

            System.out.println("Dimension: " + nombreTabla);

            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //YA SE INSERTAN VALORES A LA LISTA SIMPLE PARA EL DICCIONARIO
            //Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                //Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.get(j);

                //Se obtienen los valores que estan entre los tags '<campo></campo>'
                //Se obtiene el valor que esta entre los tags '<nombre></nombre>'
                String nombre = campo.getValue();
                lista.insertarAlFrente(nombre);
                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String tipo = campo.getChildTextTrim("y");

                //Se obtiene el valor que esta entre los tags '<valor></valor>'
                //                String valor = campo.getChildTextTrim("valor");
                System.out.println("\t" + "x" + "\t\t" + "y");
                System.out.println("\t" + nombre + "\t\t" + tipo + "\t\t");
                System.out.println(lista.mostrarlista());
            }

        }

        Palabras();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

/**
 * Parses an XML file which represents MACRO cell objects, creates corresponding
 * {@link LibraryMacro} library cells in RapidSmith, and adds them the current
 * cell library. This function can be used to augment the default {@link CellLibrary}
 * with additional cells./*from   w  w w .j  a  v a  2  s  . c  o  m*/
 * 
 * @param macroXmlPath {@link Path} to the XML file
 */
public void loadMacroXML(Path macroXmlPath) throws IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    try {
        doc = builder.build(macroXmlPath.toFile());
    } catch (JDOMException e) {
        throw new Exceptions.ParseException(e);
    }
    loadMacros(doc);
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

/**
 * Parses an XML stream which represents MACRO cell objects, creates corresponding
 * {@link LibraryMacro} library cells in RapidSmith, and adds them the current
 * cell library. This function can be used to augment the default {@link CellLibrary}
 * with additional cells.//from  w  w w.ja v  a  2  s  . c  o  m
 *
 * @param macroXmlStream {@link InputStream} to the XML file
 */
public void loadMacroXML(InputStream macroXmlStream) throws IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    try {
        doc = builder.build(macroXmlStream);
    } catch (JDOMException e) {
        throw new Exceptions.ParseException(e);
    }
    loadMacros(doc);
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadFromFile(Path filePath) throws IOException, JDOMException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(filePath.toFile());
    loadFromDoc(doc);/*from   w w w  .j a  va 2 s .  c  om*/
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadFromStream(InputStream is) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(is);
    loadFromDoc(doc);/*ww w .j  av a2s .  co  m*/
}

From source file:edu.byu.ece.rapidSmith.RSEnvironment.java

License:Open Source License

/**
 * Loads the family info file for the specified family.  The family info file contains
 * additional information not found in the XDLRC for creating device files.
 *
 * @param family family to get the family info file for
 * @return the family info xml document/*from  w  ww .j  a  v a2s. com*/
 */
public Document loadFamilyInfo(FamilyType family) throws JDOMException, IOException {
    Path path = getPartFolderPath(family).resolve(FAMILY_INFO_FILENAME);
    SAXBuilder builder = new SAXBuilder();
    return builder.build(path.toFile());
}

From source file:edu.byu.ece.rapidSmith.RSEnvironment.java

License:Open Source License

/**
 * Loads the device info file for the specified partname and family. The device info file
 * contains additional information about a specific device not found in the XDLRC file
 * or family info. For example, a list of clock pads for a device are included in the device
 * info file/*from   w w  w .  ja va 2 s  . co m*/
 *  
 * @param family Family of the part
 * @param partname Name of the part
 * @return A Document object representing the XML device info file. If device info does not exist
 *    for the specified part and family, {@code NULL} is returned.
 */
public Document loadDeviceInfo(FamilyType family, String partname) {
    String partnameNoDashes = PartNameTools.removeSpeedGrade(partname);
    Path path = getPartFolderPath(family).resolve("deviceInfo_" + partnameNoDashes + ".xml");
    SAXBuilder builder = new SAXBuilder();
    Document doc = null;
    try {
        doc = builder.build(path.toFile());
        return doc;
    } catch (JDOMException | IOException e) {
        return null;
    }
}

From source file:edu.co.usbcali.ir.util.ExtractReutersNews.java

public void extractNewsFromXml(String path) {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(path);

    String baseFileName = FilenameUtils.removeExtension(xmlFile.getName());
    String lineSeparator = System.getProperty("line.separator");

    try {//  w w w. j  a v  a  2 s. c om
        Document document = (Document) builder.build(xmlFile);
        Element rootNode = document.getRootElement();
        List listReuters = rootNode.getChildren("REUTERS");

        for (Object listElement : listReuters) {
            Element reuters = (Element) listElement;

            String newId = reuters.getAttributeValue("NEWID");
            String date = reuters.getChildText("DATE");

            List listText = reuters.getChildren("TEXT");
            Element text = (Element) listText.get(0);

            String title = text.getChildText("TITLE");
            String body = text.getChildText("BODY");

            String reuterContent = title + lineSeparator + date + lineSeparator + lineSeparator + body;
            String reuterPath = "reuters/" + baseFileName + "-" + newId + ".txt";

            WriteFile.writeFileContent(reuterContent, reuterPath);
        }
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(ExtractReutersNews.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.kit.iks.Cryptographics.Caesar.Demonstration.CryptoDemonstrationController.java

License:MIT License

/**
 * Constructor./*from  w w  w .j a  va 2 s.c  o  m*/
 * 
 * @param visualizationInfo
 */
public CryptoDemonstrationController(AbstractVisualizationInfo visualizationInfo) {
    super(visualizationInfo);

    SAXBuilder saxBuilder = new SAXBuilder();

    // obtain file object
    InputStream is = this.getClass().getResourceAsStream("/caesar/CaesarResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.cryptoResources = document.getRootElement();
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }
}