[英]How to get InnerHTML value from Xpath Result
I have the following Xpath that I can retrieve the StringValue from;我有以下 Xpath,我可以从中检索 StringValue; however, I need to get the actual inner.HTML value so that I can parse at the new line.但是,我需要获取实际的inner.HTML 值,以便我可以在新行进行解析。 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
当前结果: 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
SMITH WILLIAM <br>SMITH TOM <br>501 NW 3ND ST<br>CHICAGO IL 60073
结果: SMITH WILLIAM <br>SMITH TOM <br>501 NW 3ND ST<br>CHICAGO IL 60073
If you make the result type a node type, then you can get the innerHTML from the node.如果将结果类型设为节点类型,则可以从节点获取innerHTML。 For example:例如:
var result = document.evaluate(xpathExpression, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
alert('Xpath Result:' + result.singleNodeValue.innerHTML);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.