Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

In this page you can find the example usage for org.jdom2 Element getChildren.

Prototype

public List<Element> getChildren(final String cname) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

Usage

From source file:edd.practica1.Principal.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if (seleccionado.showDialog(null, "Abrir Archivo") == JFileChooser.APPROVE_OPTION) {
            archivos = seleccionado.getSelectedFile();

            SAXBuilder builder = new SAXBuilder();

            try {
                Document document = (Document) builder.build(archivos);
                Element rootNode = document.getRootElement();

                Element Raiz = document.getRootElement();

                List listpri = Raiz.getChildren("dimension");

                for (int i = 0; i < listpri.size(); i++) {
                    Element camp = (Element) Raiz.getChildren("dimension").get(i);
                    String Dimensiones = camp.getTextTrim();
                    Dimension = Integer.parseInt(Dimensiones);
                    System.out.println("Dimension :" + Dimensiones);

                }//w  w  w .  ja  v a2 s.  co m

                List list = rootNode.getChildren("dobles");

                for (int i = 0; i < list.size(); i++) {
                    Element scrabble = (Element) list.get(i);
                    List lista_dobles = scrabble.getChildren();
                    System.out.println("\tdobles");
                    for (int j = 0; j < lista_dobles.size(); j++) {
                        Element dobles = (Element) lista_dobles.get(j);
                        String x = dobles.getChildTextTrim("x");
                        String y = dobles.getChildTextTrim("y");
                        System.out.println("\t" + x + "\t\t" + y + "\t");
                    }
                }

                List listtri = rootNode.getChildren("triples");

                for (int i = 0; i < listtri.size(); i++) {
                    Element scrabble = (Element) listtri.get(i);
                    List lista_triples = scrabble.getChildren();
                    System.out.println("\ttriples");
                    for (int j = 0; j < lista_triples.size(); j++) {
                        Element triples = (Element) lista_triples.get(j);
                        String x = triples.getChildTextTrim("x");
                        String y = triples.getChildTextTrim("y");
                        System.out.println("\t" + x + "\t\t" + y + "\t");
                    }
                }

                for (int i = 0; i < rootNode.getChildren("diccionario").size(); i++) {
                    Element listd = (Element) rootNode.getChildren("diccionario").get(i);
                    for (int j = 0; j < listd.getChildren().size(); j++) {
                        Element diccionario = (Element) listd.getChildren("palabra").get(j);
                        String palabra = (diccionario.getTextTrim());
                        System.out.println("\t" + palabra + "\t");
                        ListasSimplesDiccionario.IngresarNodo(palabra);
                        //ListaSimpleFichasJugador.VerLista();
                    }
                }
                GenerarFichasTotales();

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

        }

    }

From source file:edd.practica1_201404218.LeerXML.java

public void cargarXML(String ruta) {

    SAXBuilder builder = new SAXBuilder();
    File archivo = new File(ruta);
    try {/* ww w  . j  ava2 s .co  m*/

        Document documento = (Document) builder.build(archivo);
        Element raiz = documento.getRootElement();

        for (int index = 0; index < raiz.getChildren("dimension").size(); index++) {
            Element campo = raiz.getChildren("dimension").get(index);
            String dimension = campo.getTextTrim();
            System.out.println(dimension);
        }

        for (int index = 0; index < raiz.getChildren("dobles").size(); index++) {
            Element doble = (Element) raiz.getChildren("dobles").get(index);

            for (int index2 = 0; index2 < doble.getChildren().size(); index2++) {
                Element casilla = (Element) doble.getChildren("casilla").get(index2);

                Posicion pos = new Posicion();
                pos.setTipo("doble");
                pos.setX(Integer.parseInt(casilla.getChildren("x").get(0).getTextTrim()));
                pos.setY(Integer.parseInt(casilla.getChildren("y").get(0).getTextTrim()));

                listaPosiciones.add(pos);

            }
        }

        for (int index = 0; index < raiz.getChildren("triples").size(); index++) {
            Element triple = (Element) raiz.getChildren("triples").get(index);

            for (int index2 = 0; index2 < triple.getChildren().size(); index2++) {
                Element casilla = (Element) triple.getChildren("casilla").get(index2);

                Posicion pos = new Posicion();
                pos.setTipo("triple");
                pos.setX(Integer.parseInt(casilla.getChildren("x").get(0).getTextTrim()));
                pos.setY(Integer.parseInt(casilla.getChildren("y").get(0).getTextTrim()));

                listaPosiciones.add(pos);

            }
        }

        for (int index = 0; index < raiz.getChildren("diccionario").size(); index++) {
            Element diccionario = (Element) raiz.getChildren("diccionario").get(index);

            for (int index2 = 0; index2 < diccionario.getChildren().size(); index2++) {
                Element palabra = (Element) diccionario.getChildren("palabra").get(index2);

                String valor = palabra.getTextTrim();
                listaPalabras.add(valor);
            }
        }

    } catch (Exception e) {

    }

}

From source file:edd.practica1_201504480.leerxml.java

Lista_Simple datos(File tipo1) {

    SAXBuilder builder = new SAXBuilder();
    try {/*from www.  j a  v a  2s.c o  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 {/*from   w  ww  . j  a v a 2  s  . co  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

private void loadMacros(Document doc) {
    // Load all macro library cells into the cell library
    Element macrosEl = doc.getRootElement().getChild("macros");

    List<Element> childrenMacros = macrosEl.getChildren("macro");

    if (childrenMacros != null) {
        for (Element macroEl : childrenMacros) {
            loadMacroFromXml(macroEl);//from  w  w  w. j a  v  a 2  s .  c o  m
        }
    }
}

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

License:Open Source License

private void loadFromDoc(Document doc) {
    // get the family of the cell library.
    readFamilyType(doc.getRootElement().getChild("family"));

    Element cellsEl = doc.getRootElement().getChild("cells");
    Map<SiteType, Map<String, SiteProperty>> sitePropertiesMap = new HashMap<>();
    // first load the leaf cells
    for (Element cellEl : cellsEl.getChildren("cell")) {
        loadCellFromXml(cellEl, sitePropertiesMap);
    }/*from  w w w . j  av a 2 s .  c  o m*/
    // then load the macro cells if any exist
    Element macrosEl = doc.getRootElement().getChild("macros");

    if (macrosEl != null) {
        List<Element> childrenMacros = macrosEl.getChildren("macro");
        if (childrenMacros != null) {
            for (Element macroEl : childrenMacros) {
                loadMacroFromXml(macroEl);
            }
        }
    }
}

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

License:Open Source License

private void loadConfigurationPropertiesFromXml(Element cellEl, LibraryCell libCell) {
    Element properties = cellEl.getChild("libcellproperties");

    if (properties != null) {
        for (Element propertyEl : properties.getChildren("libcellproperty")) {

            boolean isReadonly = propertyEl.getChild("readonly") != null;
            // for now, skip read only properties
            // TODO: revisit this
            if (isReadonly) {
                continue;
            }/*from   w  w w  .  ja  v a 2 s .c  o  m*/

            String name = propertyEl.getChildText("name");
            String deflt = propertyEl.getChildText("default");
            // TODO: integrate the min and max properties
            // String max = propertyEl.getChildText("max");
            // String min = propertyEl.getChildText("min");
            String type = propertyEl.getChildText("type");
            String valueString = propertyEl.getChildText("values");
            String[] values = valueString.isEmpty() ? new String[0] : valueString.split(", ");

            // add the configuration to the library cell
            libCell.addDefaultProperty(new Property(name, PropertyType.EDIF, deflt, isReadonly, true));
            libCell.addConfigurableProperty(new LibraryCellProperty(name, type, values, isReadonly));
        }
    }
}

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

License:Open Source License

private void loadPinsFromXml(Element cellEl, LibraryCell libCell) {
    List<LibraryPin> pins = new ArrayList<>();
    Element pinsEl = cellEl.getChild("pins");

    Pattern pinNamePattern = Pattern.compile("(.*)\\[(.*)\\]");

    for (Element pinEl : pinsEl.getChildren("pin")) {
        LibraryPin pin = new LibraryPin();
        pin.setLibraryCell(libCell);/* w  w w  .j  av  a  2  s . c  om*/
        pin.setName(pinEl.getChildText("name"));
        String pinDirection = pinEl.getChildText("direction");
        switch (pinDirection) {
        case "input":
            pin.setDirection(PinDirection.IN);
            break;
        case "output":
            pin.setDirection(PinDirection.OUT);
            break;
        case "inout":
            pin.setDirection(PinDirection.INOUT);
            break;
        default:
            throw new Exceptions.ParseException(
                    "Unrecognized pin direction while parsing the CellLibrary.xml file: " + pinDirection);
        }
        String pinType = pinEl.getChildText("type");
        pin.setPinType(pinType == null ? CellPinType.DATA : CellPinType.valueOf(pinType));
        pins.add(pin);

        // for macro cells, add the internal connection information
        if (libCell.isMacro()) {
            Matcher m = pinNamePattern.matcher(pin.getName());

            if (m.matches()) {
                ((LibraryMacro) libCell).addPinOffset(m.group(1), Integer.parseInt(m.group(2)));
            }

            List<String> internalPinNames = pinEl.getChild("internalConnections").getChildren("pinname")
                    .stream().map(el -> el.getText()).collect(Collectors.toList());
            ((LibraryMacro) libCell).addInternalPinConnections(pin, internalPinNames);
        }
    }
    libCell.setLibraryPins(pins);
}

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

License:Open Source License

private void loadInternalCellsFromXml(Element macroEl, LibraryMacro macroCell) {

    Element cellsEl = macroEl.getChild("cells");

    for (Element internalEl : cellsEl.getChildren("internal")) {
        LibraryCell libCell = library.get(internalEl.getChildText("type"));

        if (libCell == null) {
            throw new Exceptions.ParseException(
                    "Unable to find leaf library cell \"" + internalEl.getChildText("type")
                            + "\" in macro cell: \"" + macroEl.getChildText("type") + "\"");
        } else if (libCell.isMacro()) {
            throw new Exceptions.ParseException(
                    "Nested hierarchy is not supported. Cell: \"" + macroEl.getChildText("type") + "\"");
        }//from w w w.j a va2  s. c o  m

        macroCell.addInternalCell(internalEl.getChildText("name"), (SimpleLibraryCell) libCell);
    }
}

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

License:Open Source License

private void loadInternalNetsFromXml(Element macroEl, LibraryMacro macroCell) {
    Element internalNetsEl = macroEl.getChild("internalNets");

    // only add internal nets to the macro if they exist
    if (internalNetsEl != null) {

        for (Element internalNetEl : internalNetsEl.getChildren("internalNet")) {
            String name = internalNetEl.getChildText("name");
            List<String> pinNames = internalNetEl.getChild("pins").getChildren("pinname").stream()
                    .map(el -> el.getText()).collect(Collectors.toList());
            String type = internalNetEl.getChildText("type");
            if (type == null) {
                type = "WIRE";
            }/*from   www .  j  a v a2s.  c  o m*/

            macroCell.addInternalNet(name, type, pinNames);
        }
    }
}