I have an html document, and somewhere inside the document is below the table, I can get table rows and DOM java objects. Itβs not clear to me how to extract the value of a table cell when this value is a row, and also when it is a binary resource?
I use code like:
XPath xpath;
XPathExpression expr;
NodeList nodes=null;
try{
xpath = XPathFactory.newInstance().newXPath();
NodeList list = doc.getElementsByTagName("table");
expr = xpath.compile("//table/tr/td");
nodes = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
and loopiong like:
for (int i = 0; i < nodes.getLength(); i++) {
Node ln = list.item(i);
String lnText=ln.toString();
NodeList rowElements=ln.getChildNodes();
Node one=rowElements.item(0);
String oneText=one.toString();
String nodeName=one.getNodeName();
String valOne = one.getNodeValue();
But I do not see the value in the table.
<table class="data">
<tr><td>ImageName1</td><td width="50"></td><td><img src="/images/036000291452" alt="036000291452" /></td></tr>
<tr><td>ImageName2</td><td width="50"></td><td><img src="/images/36000291452" alt="36000291452" /></td></tr>
<tr><td>Description</td><td></td><td>Time Magazine</td></tr>
<tr><td>Size/Weight</td><td></td><td>14 Issues</td></tr>
<tr><td>Issuing Country</td><td></td><td>United States</td></tr>
</table>
source
share