Hi,
I'm trying to parse ugly HTML with TagSoup to extract value of a given tag. Here is the tag :
<input type="hidden" name="hash_check" value="ffc39410ed8da309408a9382450ddc85" />
I want to retrieve value of attribute "value" ("ffc39410ed8da309408a9382450ddc85")
And here is my code, in my SAX handler :
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
{
if (localName.equals("input"))
{
Log.v(TAG, Integer.toString(atts.getLength()));
if (atts.getValue("name").equals("hash_check")
{
in_input = true;
Log.v(TAG, atts.getValue("name"));
if (atts.getValue("value") != null)
Log.v(TAG,atts.getValue("value");
}
}
}
Logs are here for debugging purposes. Logcat correctly gives me "hash_check" for atts.getValue("name"), but an empty string for atts.getValue("value") although the parser is positionned to the right "input" (the one and only of my html document).
What's wrong ? Bug in TagSoup ?
Thanks
edit @bkail : thank you for your comment. Here are more details and code.
First, the URL that I'm trying to parse : http://forum.hardware.fr/hfr/Programmation/Divers-6/experts-puissant-internet-sujet_37483_1.htm
And the code used to instanciate the parser :
private static final String FORUM_URI = "http://forum.hardware.fr/hfr/Programmation/Divers-6/experts-puissant-internet-sujet_37483_1.htm";
URL hfrUrl = new URL(FORUM_URI);
Parser parser = new Parser();
HfrSAXHandler sh = new HfrSAXHandler();
parser.setContentHandler(sh);
parser.parse(new InputSource(hfrUrl.openStream()));
And finally, the whole code for my SAX parser :
public class HfrSAXHandler extends DefaultHandler
{
private boolean in_input = false;
private static final String TAG = "hfr4droid";
@Override
public void startDocument() throws SAXException
{
Log.v(TAG, "start of parsing");
}
@Override
public void endDocument() throws SAXException
{
}
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
{
if (localName.equals("input"))
{
Log.v(TAG, Integer.toString(atts.getLength()));
if (atts.getValue("name") != null)
{
in_input = true;
Log.v(TAG, atts.getValue("name"));
if (atts.getValue("value") != null)
Log.v(TAG, Integer.toString(atts.getValue("value")));
}
}
}
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
if (localName.equals("input"))
in_input = false;
}
}
Thanks for giving it a try.