Analizar elementos de la lista de archivos XML con XML simple en Android

Tengo que analizar un archivo xml grande con XML SImple, (realmente quiero utilizar XML simple). Creé objetos con XSD, los convirtieron de JAXB específico a objetos especificados específicos de SimpleXML.

El XML se ve así:

<House> <MainLevel Name="~#editRoom" IsHidden="false"> <ChildLevel Name="Television" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="Chair" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="Table"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="ChamberName" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="ChamberName" Category="Bathroom"> <string>BathTub</string> </ChildLevel> <ChildLevel Name="Door", Category="DiningRoom"> <boolean>isOpen</boolean> </ChildLevel> </MainLevel> <MainLevel Name="~#editRoom" IsHidden="false"> <ChildLevel Name="Television" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="Chair" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="Table" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="ChamberName" Category="Livingroom"> <string>TestRoom</string> </ChildLevel> <ChildLevel Name="ChamberName" Category="Bathroom"> <string>BathTub</string> </ChildLevel> <ChildLevel Name="Door"> <boolean>isOpen</boolean> </ChildLevel> </MainLevel> </House> 

¿Cuáles son sus sugerencias? Por favor ayuda.Thx.

Es mejor escribir 3 clases:

  1. Una clase House , (= la raíz) que contiene una lista (en línea) de MainLevel
  2. Una clase MainLevel , que contiene una lista (en línea) de todos los ChildLevel
  3. Una clase ChildLevel , que contiene el valor

Aquí hay un pseudocódigo :

 @Root(...) public class House { @ElementList(inline = true, ...) private List<MainLevel> levels; // ... } public class MainLevel { @Attribute(name = "Name") private String name; @Attribute(name = "IsHidden") private bool hidden; @ElementList(inline = true, ...) private List<ChildLevel> childLevels; // ... } public class ChildLevel { @Attribute(name = "Name") private String name; @Attribute(name = "Category", required = false) private String category; // ... } 

Dado que un ChildLevel puede tener diferentes tipos, hay que tener cuidado con esto. O bien implementar todos los tipos y marcarlos como no es necesario, o hacer subclases.

  • Android, Almacenamiento y recuperación de texto
  • ¿Cómo cambiar el color del pulgar en el buscador?
  • Icono de elemento del cajón de navegación que no muestra el color original
  • Barra de búsqueda personalizada tiene una brecha entre el pulgar y el progreso
  • "Unhandled Event Loop Exception" al hacer algo en Android XML
  • ¿Cómo eliminar la barra de acción azul en Android?
  • Include tag en el archivo xml de la programación de Android
  • ¿Por qué el nombre de archivo xml de android debe contener sólo letras minúsculas y dígitos ()?
  • OnItemClickListener de spinner
  • Android: ¿es posible agregar un enlace que se puede hacer clic en un recurso de cadena
  • No se puede arrastrar DrawerLayout desde ListView
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.