|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Re: Looping through attributes- successHello again guys, Thanks to all of you for the great ideas. By using combination of the bits of ideas you all supplied I have been able to achieve the goal I combine the suggestions of both Mike and grzegorz; here is the code snip I used: List checkDomain = document.getRootElement().getChildren(); for (int i = 0; i < checkDomain.size(); i++) { Element next = (Element)checkDomain.get(i); domainName= next.getAttribute("domain").getValue(); if (domainName.equals(user_enteredValue)){ System.out.println("Found domain") break; } // when the last value is checked and nothing found if(!domainName.equals(user_enteredValue)&&i==checkDomain.size()-1){ System.out.println("The domain does not exists"); break; } Once again thanks to all of you! and to all jdom group! Bashiro Drammen-Norway --- On Wed 01/23, Grzegorz Kaczor < grzegorz.kaczor@... > wrote: From: Grzegorz Kaczor [mailto: grzegorz.kaczor@...] To: bashiro@... Cc: jdom-interest@... Date: Wed, 23 Jan 2008 10:43:57 +0100 Subject: Re: [jdom-interest] Looping through attributes No :).boolean found = falsefor (...) { if ("domain".equals(...)) { ... found = true; break; }}So not found will be displayed once.But better use Michael's way, it is ok.String value = element.getAtttibute("domain");if (value == null || (!value.equals(dom.trim()))) display "not found"Regards,Grzegorz2008/1/22, Bashiro <bashiro@...>:>>> Thanks,>> Theoriticaly yes, but practically no!> When boolean is false, that is when the value of an attribute is not found,> jdom displays as many "not founds" as the number of contens in the xml.>> I am beguining to think if I should combine HashMap so that Hashmap will check before passing it on to the jdom code.> I thought jdom could do this easier....>> Bashiro> Drammen-Norway>>>>> --- On Tue 01/22, Grzegorz Kaczor < grzegorz.kaczor@... > wrote:> From: Grzegorz Kaczor [mailto: grzegorz.kaczor@...]> To: bashiro@...> Cc: jdom-interest@...> Date: Tue, 22 Jan 2008 20:33:37 +0100> Subject: Re: [jdom-interest] Looping through attributes>> Hi>> Thanks for the mail.> And thanks for warning me about the else clause.> Do you have any suggestions on how to let jdom> display a message when the attribute is not dound ?To have a boolean variable 'found' initialized to false before theloop, set it to true on find and use 'break' instead of 'return'? Justa suggestion.Grzegorz>> _______________________________________________> No banners. No pop-ups. No kidding.> Make My Way your home on the Web - http://www.myway.com>>> _______________________________________________> To control your jdom-interest membership:> http://www.jdom.org/mailman/options/jdom-interest/youraddr@...>-- "Choæ tyle wiemy w³asnym do¶wiadczeniem:W nas jest Raj, Piek³o - i do obu - szlaki."J.K. _______________________________________________ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@... |
| Free Forum Powered by Nabble | Forum Help |