Solution 1 :

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);

Problem :

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

Comments

Comment posted by Jack Fleeting

Can you post the html you’re working with and your desired output?

Comment posted by epascarello

SHouldn’t

Comment posted by Tim Goodman

Is there a reason you’re using

Comment posted by Tennis

sorry Tim, that was a typo, the value has been changed to ‘result.stringValue.’

Comment posted by Tim Goodman

For future reference, it’s helpful to make sure the code in your question is enough for someone to run (in this case, I get an error that

Comment posted by Tennis

Perfecto! Thank you Tim! Greatly appreciate the extra effort. I will be sure to include supporting code going forward.

By