I am trying to extract the text value and size value in the row tag from this xml.
<items>
<item>
<table>
<row text="foo" size="4"/>
</table>
</item>
</items>
I was able to get the values for this xml:
<items>
<item>
<textbox text="foo">
</item>
</items>
with this code.
NodeList textbox = element.getElementsByTagNa开发者_JAVA技巧me("textbox");
line = (Element) textbox.item(0);
String textbox_text = line.getAttribute("text");
can someone tell me how should I go about this?
NodeList items = element.getElementsByTagName("items");
for(int i=0 i<items.getLength(); i++)
{
NodeList item = items.item(i).getElementsByTagName("item");
for(int j=0 j<item.getLength(); j++)
{
NodeList table = item.item(j).getElementsByTagName("table");
for(int k=0 i<table.getLength(); k++)
{
NodeList rows = table.item(k).getElementsByTagName("rows");
for(int h=0 i<table.getLength(); h++)
{
rows.item(h).getAtribbute("text");
rows.item(h).getAtribbute("size");
}
}
}
}
something like that
I suppose,
NodeList textbox = element.getElementsByTagName("row");
line = (Element) textbox.item(0);
String textbox_text = line.getAttribute("text");
String textbox_size = line.getAttribute("size");
If you want to use textbox_size as a number, you might want to cast it as an int.
If this code fails, it could well be due to the seemingly random tag making this XML invalid.
精彩评论