Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Hotel{
- private String nombre;
- public Hotel(String nombre){
- this.nombre=nombre;
- }
- public String getNombre(){
- return nombre;
- }
- public String consultarCategorias(){
- String consola="Listado de Categorias:"+"\n"+"-------------------------------------------------------------------------------------------------------------"+"\n";
- try{
- DocumentBuilder documentBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document doc=documentBuilder.parse(new InputSource(new FileInputStream("gestorBD\\hoteles\\"+this.getNombre()+"\\listaCategorias.xml")));
- Element elementRaiz =doc.getDocumentElement();
- NodeList hijos=elementRaiz.getChildNodes();
- if(hijos.getLength()==0){
- return "No Hay categorias Inscritas";
- }
- for(int i=0;i<hijos.getLength();i++){
- Node nodo=hijos.item(i);
- if(nodo instanceof Element){
- Element eNode=(Element)nodo;
- String nombre=(i+1) + "." + "Categoria: " + eNode.getAttributeNode("nombre").getValue()+"\t";
- String suplemento="Precio de la categoria: " + eNode.getChildNodes().item(0).getTextContent()+" Euros"+"\t";
- String area="Area de la habitacion: " + eNode.getChildNodes().item(1).getTextContent()+"[metros cuadrados]";
- consola+=nombre+suplemento+area+"\n";
- }
- }
- consola+="-------------------------------------------------------------------------------------------------------------";
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- return consola;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement