View Single Post
  #5 (permalink)  
Old 11-03-2007, 02:50 AM
gvi gvi is offline
Member
 
Join Date: Oct 2007
Posts: 6
gvi is on a distinguished road
Murali I have another question

from the xml below I need the following output

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>
film|entertainment
film|drama
film|music
sitcom|entertainment
sitcom|tv

But the code I have displays the output as

film|entertainment
film|drama
film|music
film|entertainment
film|tv

sitcom|entertainment
sitcom|drama
sitcom|music
sitcom|entertainment
sitcom|tv

And this is the code I have

Code:
static void GetItem(Document doc){ Element root = doc.getDocumentElement(); Element[] items = getElementsByTagNameNR(root,"Item"); for(int i=0;i<items.length;i++){ String itemIDStr = items[i].getAttribute("ItemID"); NodeList nl = doc.getElementsByTagName("Category"); for (int j = 0; j < nl.getLength(); j++){ Node n = nl.item(j); NodeList nll = n.getChildNodes(); for(int k=0; k<nll.getLength(); k++){ Node nn = nll.item(k); streamItemCategory.println(itemIDStr + nn.getNodeValue() + columnSeparator); } } }
I know I have to check somewhere where when the itemId changes it no more should read the previous ones categories but not sure where to include the condition

As again your help needed

Thanks
G

Last edited by JavaBean : 11-03-2007 at 09:37 AM.
Reply With Quote