How to get InnerHTML value from Xpath Result

Tennis :

I have the following Xpath that I can retrieve the StringValue from; however, I need to get the actual inner.HTML value so that I can parse at the new line. How would I go about doing this?

var html = '<table><tbody><tr><td width="33%">SMITH WILLIAM  <br>SMITH TOM  <br>501 NW 3ND ST<br>CHICAGO IL 60073</td></tr></tbody></table>';


var Xpath = '//table/tbody/tr/td[1]'; 
var parser = new DOMParser();
var doc = parser.parseFromString(html,'text/html');
result = doc.evaluate(Xpath, doc, null, XPathResult.STRING_TYPE, null);
alert('Xpath Result:' + result.stringValue); //NEED HTML i.e. HTML.Value

Current Outcome: SMITH WILLIAM SMITH TOM 501 NW 3ND STCHICAGO IL 60073

Desired Outcome: SMITH WILLIAM <br>SMITH TOM <br>501 NW 3ND ST<br>CHICAGO IL 60073

Tim Goodman :

If you make the result type a node type, then you can get the innerHTML from the node. For example:

var result = document.evaluate(xpathExpression, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
alert('Xpath Result:' + result.singleNodeValue.innerHTML);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29880&siteId=1