Advertisement
daniel199410

Consultar Categorias

May 18th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. public class Hotel{
  2. private String nombre;
  3.    
  4.     public Hotel(String nombre){
  5.         this.nombre=nombre;
  6.     }
  7.    
  8.     public String getNombre(){
  9.         return nombre;
  10.     }
  11.    
  12.     public String consultarCategorias(){
  13.        String consola="Listado de Categorias:"+"\n"+"-------------------------------------------------------------------------------------------------------------"+"\n";
  14.        try{
  15.             DocumentBuilder documentBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
  16.             Document doc=documentBuilder.parse(new InputSource(new FileInputStream("gestorBD\\hoteles\\"+this.getNombre()+"\\listaCategorias.xml")));
  17.             Element elementRaiz =doc.getDocumentElement();
  18.             NodeList hijos=elementRaiz.getChildNodes();
  19.             if(hijos.getLength()==0){
  20.                 return "No Hay categorias Inscritas";
  21.             }
  22.             for(int i=0;i<hijos.getLength();i++){
  23.                 Node nodo=hijos.item(i);
  24.                 if(nodo instanceof Element){
  25.                     Element eNode=(Element)nodo;
  26.                     String nombre=(i+1) + "." + "Categoria: " + eNode.getAttributeNode("nombre").getValue()+"\t";
  27.                     String suplemento="Precio de la categoria: " + eNode.getChildNodes().item(0).getTextContent()+" Euros"+"\t";
  28.                     String area="Area de la habitacion: " + eNode.getChildNodes().item(1).getTextContent()+"[metros cuadrados]";
  29.                     consola+=nombre+suplemento+area+"\n";
  30.                 }              
  31.             }
  32.             consola+="-------------------------------------------------------------------------------------------------------------";
  33.         }catch(Exception e){
  34.             System.out.println(e.getMessage());
  35.         }
  36.        return consola;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement