Based on the OP's comments to posted answers (and my curiosity as to why this simple thing would not work), here is my suggestion:
Using the XPath expression suggested by @Anthony, I was able to successfully load the comment node with the following JS function:
function SelectComment(s)
{
var xDoc = new ActiveXObject("MSXML2.DOMDocument.6.0");
if (xDoc)
{
xDoc.loadXML(s);
var selNode = xDoc.selectSingleNode("/table/length/following::comment()[1]");
if (selNode != null)
return selNode.text;
else
return "";
}
}
Sample invocation:
SelectComment("<table><length> 12</length><!--Some comment here--></table>");
Output:
"Some comment here"
Notes:
a. Your MSXML version may vary. Please use appropriately.
b. This kind of code is definitely not recommended because it works only on IE. However, since this is your explicitly stated requirement, I have used the ActiveXObject.
c. You have not mentioned in your comments what fails in the suggested XPath expressions. My guess is that you are not querying the text
property of the retrieved node. Keep in mind that the SelectSingleNode always returns an IXmlNode
and you need to query its data
or text
properties.