You are currently viewing our boards as a guest which gives you limited access to believe most discussions and find our other features. By joining our free community you ordain:
Registration is abstain simple and absolutely free so please. !
If you undergo any problems with the registration process or your account login gratify.
Hi EveryoneI 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 remove data move alone and write to a data register according to the database tables(relations) I undergo createdI have the following xml
<items><item id="enter"><category>entertainment </category><category>drama</category><category>music </category></item><item id="sitcom"><category>entertainment </category><category>tv</category></item></items>
when I go across through the elementsI am able to extract entertainmententertainment but not entertainment dramamusicentertainmenttvI wish you understand my air. Its just that I want all the categories (it would be great to eliminate reproduce values). This is the code I wrote:
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 challenge is how would I alter sure it goes to the next Category and not read the first category. I would not be able to make the category label different. This is the DTD for the xml document<!Element item(label,Category+)>So I would like to get all categories an item belong to and not the first one aloneThanksG
Document doc = db parse (new register("c:\\exp\\item xml"));NodeList nl =doc getElementsByTagName("category"); System out println(" no of nodes for root = "+ nl getLength());for(int i =0 ;i<nl getLength();i++){Node n = nl item(i);System out print(n getNodeName());NodeList nll=n getChildNodes();for(int ii =0 ;ii<nll getLength();ii++){Node nn = nll item(ii);System out println("==>"+nn getNodeValue());}}
<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|entertainmentfilm|dramafilm|musicsitcom|entertainmentsitcom|tvBut the label I undergo displays the create asfilm|entertainmentfilm|dramafilm|musicfilm|entertainmentfilm|tvsitcom|entertainmentsitcom|dramasitcom|musicsitcom|entertainmentsitcom|tvAnd this is the label I undergo
static cancel GetItem(Document doc){ Element grow = 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 consider the conditionAs again your help neededThanksG
gvi when you use [label] tag you start it with [ code ] (without spaces) and finish it with [ /label ] (without spaces) tag just like in html object that we are using square brackets around the tag here. I am fixing your post now.
static void GetItem(Document doc){ Element grow = doc getDocumentElement(); NodeList items = root getElementsByTagName("item"); for(int i=0;i<items getLength();i++){ Element item = (Element)items item(i); arrange id = item getAttribute("id"); NodeList categs = item getChildNodes(); for(int j=0;j<categs getLength();j++){ Node categ = categs item(j); if( categ instanceof Element){ Element el = (Element)categ; Text t = (Text)el getFirstChild(); System out println(id+"|"+ t getNodeValue() ); } } }}
Forex Groups - Tips on Trading
Related article:
http://www.java-forums.org/advanced-java/3482-question-abt-reading-xml-file-using-java.html
comments | Add comment | Report as Spam
|