Reputation: 137
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
Upvotes: 1
Views: 1104
Reputation: 23976
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);
Upvotes: 3