RE: Looping through attributes

"Bashiro"<[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
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 ?

Thanks
Bashiro
Drammen-Norway

 --- On Tue 01/22, Michael Kay < [email protected] > wrote:
From: Michael Kay [mailto: [email protected]]
To: [email protected], [email protected]
Date: Tue, 22 Jan 2008 10:13:31 -0000
Subject: RE: [jdom-interest] Looping through attributes

I can't see why you aren't using getAttribute() to get the attribute byname, which would surely be much simpler. But your actual bug is that youare executing the "else" code ("Domain does not exist") once for everynon-matching attribute (it's inside the while loop). A dangling else bug.Take more care over indentation in future.Michael Kayhttp://www.saxonica.com/> -----Original Message-----> From: [email protected] > [mailto:[email protected]] On Behalf Of Bashiro> Sent: 22 January 2008 02:01> To: [email protected]> Subject: RE: [jdom-interest] Looping through attributes> > > > Hello,> Thanks for the reply. I appreciate this;> > here is the snip code;>   > > public  void searchDomain(Element element, String dom) {>     >     List attributes = element.getAttrib
 utes();>     >     if (!attributes.isEmpty()) {>       Iterator iterator = attributes.iterator();>       while (iterator.hasNext()) {>         Attribute attribute = (Attribute) 
iterator.next();>         String name = attribute.getName();>         String value = attribute.getValue();>   >             if(name.equals("domain")&&value.equals(dom.trim())){>              jTextArea1.append(" Domain Exists: " + value + "\n"); >              return;>             }>     >         else {>            >           System.out.println("Domain does not exist  " +(dom));      >            } >         }>        >     }> >   }> > Thanks> Bashiro> Drammen-Norway> >  --- On Mon 01/21, Michael Kay < [email protected] > wrote:> From: Michael Kay [mailto: [email protected]]> To: [email protected], [email protected]> Date: Mon, 21 Jan 2008 21:09:29 -0000> Subject: RE: [jdom-interest] Looping through attributes> > Show us your input, show us your code, and we can help you > understand
  whereyou have gone wrong. JDOM doesn't do anything > unless you ask it to.Michael Kayhttp://www.saxonica.com/> > > Hello folks,> There is one thing bodering me and I hope > someone could 
help.> When I loop through attributes to search > for values. How do I > stop jdom from not printing on any > attribute that it loops through.> > Example:> I search for an > attribute "domain" when the corresponding > value matches > jdom returns found. But when not found; it > prints on all > attributes and I get a list of not found, not > found, > corresponding to the number of attributes in the documents.> > > What code or how do i tell jdom to print "not found" only > one time?> > Bashiro> Drammen-Norway> > > > _______________________________________________> 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/o
 ptions/jdom-interest/youraddr@you> > rhost.com> > _______________________________________________> 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@you> rhost.com

_______________________________________________
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/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.