I have the part of the HTML page below and you want to extract the contents of the div tag, its id hiddenDivHL using DOM Parser:
Part of the HTML page:
<div id='hiddenDivHL' style='display:none'>http://74.127.61.106/udayavaniIpad/details.php?home=0&catid=882&newsid=123069[InnerSep]http://www.udayavani.com/udayavani_cms/gall_content/2012/1/2012_1$thumbimg117_Jan_2012_000221787.jpg[InnerSep]ಯುವಜನತೆಯಿಂದ ಭವ್ಯಭಾರತ[OuterSep]
So far I have used the code below, but I cannot use getElementById . How to do it?
DOM Parser:
try { URL url = new URL("http://74.127.61.106/udayavaniIpad/details_android.php?home=1&catid=882&newsid=27593"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("item"); name = new TextView[nodeList.getLength()]; website = new TextView[nodeList.getLength()]; category = new TextView[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); name[i] = new TextView(this); Element fstElmnt = (Element) node; NodeList nameList = fstElmnt.getElementsByTagName("hiddenDivHL"); Element nameElement = (Element) nameList.item(0); nameList = nameElement.getChildNodes(); name[i].setText("Name = " + ((Node) nameList.item(0)).getNodeValue()); layout.addView(name[i]); } } catch (Exception e) { System.out.println("XML Pasing Excpetion = " + e); } setContentView(layout); }
source share