Hi Everyone
I am not an advanced user and pardon me if this is not an advanced topic for you.
My requirement is this. I have a xml file from which I have to extract data part alone and write to a data file according to the database tables(relations) I have created
I have the following xml
|
Code:
|
<items>
<item id="film">
<category>entertainment </category>
<category>drama</category>
<category>music </category>
</item>
<item id="sitcom">
<category>entertainment </category>
<category>tv</category>
</item>
</items> |
when I traverse through the elements
I am able to extract entertainment
entertainment
but not
entertainment
drama
music
entertainment
tv
I hope you understand my issue. Its just that I want all the categories (it would be great to eliminate duplicate values).
This is the code I wrote:
|
Code:
|
for (int i =0; i< items.length; i++)
{
String catStr = getElementTextByTagNameNR(items[i], "Category");
String catStr1 = getElementTextByTagNameNR(items[i], "Category");
String catStr2 = getElementTextByTagNameNR(items[i], "Category");
String catStr3 = getElementTextByTagNameNR(items[i], "Category");
System.out.println(catStr + catStr1+ catStr2 + catStr3 + columnSeparator);
} |
My question is how would I make sure it goes to the next Category and not read the first category. I would not be able to make the category name different.
This is the DTD for the xml document
<!Element item(Name,Category+)>
So I would like to get all categories an item belong to and not the first one alone
Thanks
G