Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25556
| From | Daryn <darynholmes@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | How do you get a class attribute from a span tag |
| Date | 2011-02-02 10:12 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <65d14e2b-f00c-49dc-a0a4-a6cd33177596@f21g2000vbg.googlegroups.com> (permalink) |
Hi,
I am using org.w3c.dom to extract values from some HTML.
Some html with a span tag like this: <SPAN class='item c123'>-</SPAN>
My code is like this:
StringReader reader = new StringReader(html());
InputSource inputSource = new InputSource(reader);
SAX2DOM sax2dom = new SAX2DOM();
Parser tagSoupParser = new Parser();
tagSoupParser.setContentHandler(sax2dom);
tagSoupParser.setFeature(Parser.namespacesFeature, false);
tagSoupParser.parse(inputSource);
Document document = (Document) sax2dom.getDOM();
NodeList trElements = document.getElementsByTagName("span");
Node node = trElements.item(0);
I would like to do something like this:
((Element)node).getAttributes().getNamedItem("class")
But that throws an "com.sun.org.apache.xerces.internal.dom.TextImpl
cannot be cast to org.w3c.dom.Element" exception.
How can I get the value of the class attribute in that span tag?
Thanks in advance!
Back to comp.lang.java.programmer | Previous | Next | Find similar
How do you get a class attribute from a span tag Daryn <darynholmes@gmail.com> - 2011-02-02 10:12 -0800
csiph-web