i have a question: i use to only "read" easy XML-code containing Only "some childs" like this one:
<xml id="cafeMenuXML">
<cafemenu>
<item>Potato Salad</item>
<item1>Two Eggs, any style</item1>
<item2>Joe's Famous Peppers and Eggs</item2>
<item3>French toast</item3>
</cafemenu>
</xml>
And I only chose DOM and just look this up with:
Public String Item1, Item2 Item3;
//. . .
for (int i= 0; i< nodelist.getLength(); i++) {
Node nNode = nodelist.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
Item1 = getNode("item1");
Item2 = getNode("item2");
Item3 = getNode("item3");
}
private CharSequence getNode(String, Element eElement) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
BUT I cant understand HOW I do get the item when I have this type of XML-file:
<xml id="cafeMenuXML">
<cafemenu>
<entree>
<row>
<item>Potato Salad</item>
<price>2.95</price>
</row>
<row>
<item>Joe's French Fries</item>
<price>5.50</price>
</row>
<row>
<item>Huevos Rancheros</item>
<price>6.50</price>
<row>
</entree>
</cafemenu>
</xml>
can you please, please help me in some directions ? :-)
No comments:
Post a Comment