Вы можете снова разыграть предмет NodeList
с помощью Element
, а затем использовать getElementsByTagName();
из класса Element
.Лучший подход - сделать Cell Object
в вашем проекте вместе с такими полями, как Direction
, Switch
, Color
.Затем получите ваши данные примерно так:
String direction [];
NodeList cell = document.getElementsByTagName("Cell");
int length = cell.getLength();
direction = new String [length];
for (int i = 0; i < length; i++)
{
Element element = (Element) cell.item(i);
NodeList direction = element.getElementsByTagName("Direction");
Element line = (Element) direction.item(0);
direction [i] = getCharacterDataFromElement(line);
// remaining elements e.g Switch , Color if needed
}
Где ваш getCharacterDataFromElement()
будет следующим.
public static String getCharacterDataFromElement(Element e)
{
Node child = e.getFirstChild();
if (child instanceof CharacterData)
{
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "";
}