wood burning stoves 2.0*
The moose likes Java in General and the fly likes fun with getAttribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "fun with getAttribute" Watch "fun with getAttribute" New topic
Author

fun with getAttribute

Mark Ayad
Greenhorn

Joined: Sep 06, 2001
Posts: 3
Hi All,
Im having problems with this snippet of code. I'm trying
to get all the key value pairs for a html tag element using
HTMLEditorKit.ParserCallback.
public void showAttributes(MutableAttributeSet attrSet)
{
Enumeration attrEnum = attrSet.getAttributeNames();

while(attrEnum.hasMoreElements())
{
String s = (attrEnum.nextElement().toString());

if(s != null)
{
attrSet.getAttribute(s); !!always returns null!!
}
)
}
}
I can Enumeration the AttributeSet which brings back all
the attribute names (s) contained in the tag. However
attrSet.getAttribute(s); !!always returns null!!.
Looking a bit deeper say the tag is < a href="index.htm" target="blank">
then the attribute names is:
href
target
now you would thought that attrSet.getAttribute("href") would bring
back index.htm, but no it returns null.
So I tried attrSet.getAttribute(HTML.Attribute.HREF) which worked.
....And so it seems that if the attribute name is defined in Class HTML.Attribute
then you can't obtain the attribute value using attrSet.getAttribute(s).
However if the attribute name is not present in Class HTML.Attribute then
attrSet.getAttribute(s) works fine.
One very bad solution is to use a lookup
if(name.equals("action"))
{
return HTML.Attribute.ACTION;
}
else if(name.equals("align"))
{
return HTML.Attribute.ALIGN;
}
else if(name.equals("alink"))
{
return HTML.Attribute.ALINK;
}

.... but this is a log if - else ladder

Any ideas??

Thanks


[This message has been edited by Jim Yingst (edited October 11, 2001).]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The method you want is in the class javax.swing.text.html.HTML:
<pre>
HTML.Attribute attr = HTML.getAttributeKey(name);
return attr;
</pre>


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fun with getAttribute
 
Similar Threads
Recreating c:out
Property file is cached
Configure EL function in tag library descriptor?
Customizing FormPropertyConfig
Displaying DOM using swing