I'm involved with a project that is moving from IE8 to IE9. I learned that IE9 and above no longer supports selectNodes() for performing xPath queries. In response, I turned to Google's Wicked-Good-XPath, a native JavaScript xpath library, to get access to the Evaluate XPath function.
The XML document I'm trying to execute the XPath query against looks like:
<?xml version="1.0" encoding="UTF-8"?>
<SearchResults xmlns="http://tempuri.org/SearchResults.xsd">
<ADISResults>
<ADISID>123456</ADISID>
<Title>...</Title>
<FN>...</FN>
<MN />
<LN>...</LN>
<Suffix />
<PreferredState>...</PreferredState>
<CouncilCity>...</CouncilCity>
<Lost>...</Lost>
<Deceased>...</Deceased>
<CategoryID>...</CategoryID>
<Category>...</Category>
<Classification>....</Classification>
<Affiliation>...</Affiliation>
<Individual>...</Individual>
<DisplayName>...</DisplayName>
<Selected>...</Selected>
<WGSelected>...</WGSelected>
<SortName>...</SortName>
<DMASEntityDesc>...</DMASEntityDesc>
<DMASSourceDesc>...</DMASSourceDesc>
<NoSolicit>...</NoSolicit>
<NoMail>...</NoMail>
<Region>...</Region>
<Region1>...</Region1>
</ADISResults>
<ResultTotals>
<MaxResults>...</MaxResults>
<NumResults>...</NumResults>
</ResultTotals>
</SearchResults>
Since I want to select any/all ADISResults
nodes, my XPath query, taking the namespace into consideration, looks like: //*[local-name()='ADISResults']
. The query doesn't seem to be the problem, since it produces the expected results at XPathTester.
My JavaScript calling Wicked-Good-XPath and its evaluate function looks like:
wgxpath.install();
var xPathQuery = "//*[local-name()='ADISResults']";
var xpr = xdoc.evaluate(xPathQuery, xdoc, null, XPathResult.ANY_TYPE, null);
var nl = xpr.singleNodeValue;
But if I run the code above, and inspect the XPathResult, var xpr
, I see [Exception: TypeError]
for many of the variable's properties, including xpr.singleNodeValue
. Ultimately, I'm trying to retrieve a list of matching xml nodes into var nl
.
What am I doing wrong?
Update 3/4/2014:
After performing more testing, I think the problem has to lie in my assumptions about the xdoc
object I'm using. It is passed to the success
handler of a jQuery AJAX call to an ASP.NET ajax handler. In inspecting the xdoc
object's properties, it seems like a valid XML document object. Are there some specific properties on which exaluate
relies that I should be aware of?
All the other arguments and their types seem to be in line with W3 documentation, so that leave the xdoc
object as the sole suspect.
Update 2 3/4/2014:
Ok. This has to be something subtle within the xdoc
object itself. I've generated a dump of it's contents in the hopes that it may help in figuring this out.
webkitFullscreenElement: null;
webkitFullscreenEnabled: true;
webkitCurrentFullScreenElement: null;
webkitFullScreenKeyboardInputAllowed: false;
webkitIsFullScreen: false;
childElementCount: 1;
lastElementChild: [object Element];
firstElementChild: [object Element];
children: [object HTMLCollection];
onwaiting: null;
onvolumechange: null;
ontimeupdate: null;
onsuspend: null;
onsubmit: null;
onstalled: null;
onshow: null;
onselect: null;
onseeking: null;
onseeked: null;
onscroll: null;
onreset: null;
onratechange: null;
onprogress: null;
onplaying: null;
onplay: null;
onpause: null;
onmousewheel: null;
onmouseup: null;
onmouseover: null;
onmouseout: null;
onmousemove: null;
onmouseleave: null;
onmouseenter: null;
onmousedown: null;
onloadstart: null;
onloadedmetadata: null;
onloadeddata: null;
onload: null;
onkeyup: null;
onkeypress: null;
onkeydown: null;
oninvalid: null;
oninput: null;
onfocus: null;
onerror: null;
onended: null;
onemptied: null;
ondurationchange: null;
ondrop: null;
ondragstart: null;
ondragover: null;
ondragleave: null;
ondragenter: null;
ondragend: null;
ondrag: null;
ondblclick: null;
oncuechange: null;
oncontextmenu: null;
onclose: null;
onclick: null;
onchange: null;
oncanplaythrough: null;
oncanplay: null;
oncancel: null;
onblur: null;
onabort: null;
currentScript: null;
webkitHidden: true;
webkitVisibilityState: hidden;
hidden: true;
visibilityState: hidden;
onwheel: null;
onwebkitpointerlockerror: null;
onwebkitpointerlockchange: null;
onwebkitfullscreenerror: null;
onwebkitfullscreenchange: null;
onselectstart: null;
onselectionchange: null;
onsearch: null;
onreadystatechange: null;
onpaste: null;
oncut: null;
oncopy: null;
onbeforepaste: null;
onbeforecut: null;
onbeforecopy: null;
webkitPointerLockElement: null;
compatMode: CSS1Compat;
selectedStylesheetSet: null;
preferredStylesheetSet: null;
characterSet: null;
readyState: interactive;
defaultCharset: undefined;
charset: undefined;
location: null;
lastModified: 03/04/2014 22:26:49;
anchors: [object HTMLCollection];
forms: [object HTMLCollection];
links: [object HTMLCollection];
applets: [object HTMLCollection];
images: [object HTMLCollection];
head: null;
body: null;
cookie: ;
URL: http://localhost:58748/AJAXHandlers/AdvSrch.ashx;
domain: localhost;
referrer: ;
title: ;
styleSheets: [object StyleSheetList];
defaultView: null;
documentURI: http://localhost:58748/AJAXHandlers/AdvSrch.ashx;
xmlStandalone: false;
xmlVersion: 1.0;
xmlEncoding: null;
inputEncoding: null;
documentElement: [object Element];
implementation: [object DOMImplementation];
doctype: null;
parentElement: null;
textContent: null;
baseURI: http://localhost:58748/AJAXHandlers/AdvSrch.ashx;
localName: null;
prefix: null;
namespaceURI: null;
ownerDocument: null;
nextSibling: null;
previousSibling: null;
lastChild: [object Element];
firstChild: [object Element];
childNodes: [object NodeList];
parentNode: null;
nodeType: 9;
nodeValue: null;
nodeName: #document;
createElement: function createElement() { [native code] };
createDocumentFragment: function createDocumentFragment() { [native code] };
createTextNode: function createTextNode() { [native code] };
createComment: function createComment() { [native code] };
createCDATASection: function createCDATASection() { [native code] };
createProcessingInstruction: function createProcessingInstruction() { [native code] };
createAttribute: function createAttribute() { [native code] };
getElementsByTagName: function getElementsByTagName() { [native code] };
importNode: function importNode() { [native code] };
createElementNS: function createElementNS() { [native code] };
createAttributeNS: function createAttributeNS() { [native code] };
getElementsByTagNameNS: function getElementsByTagNameNS() { [native code] };
getElementById: function getElementById() { [native code] };
createEvent: function createEvent() { [native code] };
createRange: function createRange() { [native code] };
createNodeIterator: function createNodeIterator() { [native code] };
createTreeWalker: function createTreeWalker() { [native code] };
execCommand: function execCommand() { [native code] };
queryCommandEnabled: function queryCommandEnabled() { [native code] };
queryCommandIndeterm: function queryCommandIndeterm() { [native code] };
queryCommandState: function queryCommandState() { [native code] };
queryCommandSupported: function queryCommandSupported() { [native code] };
queryCommandValue: function queryCommandValue() { [native code] };
getElementsByName: function getElementsByName() { [native code] };
elementFromPoint: function elementFromPoint() { [native code] };
caretRangeFromPoint: function caretRangeFromPoint() { [native code] };
getSelection: function getSelection() { [native code] };
getCSSCanvasContext: function getCSSCanvasContext() { [native code] };
getElementsByClassName: function getElementsByClassName() { [native code] };
querySelector: function querySelector() { [native code] };
querySelectorAll: function querySelectorAll() { [native code] };
webkitExitPointerLock: function webkitExitPointerLock() { [native code] };
evaluate: function evaluate() { [native code] };
adoptNode: function adoptNode() { [native code] };
getOverrideStyle: function getOverrideStyle() { [native code] };
registerElement: function registerElement() { [native code] };
webkitCancelFullScreen: function webkitCancelFullScreen() { [native code] };
webkitExitFullscreen: function webkitExitFullscreen() { [native code] };
createExpression: function createExpression() { [native code] };
createNSResolver: function createNSResolver() { [native code] };
insertBefore: function insertBefore() { [native code] };
replaceChild: function replaceChild() { [native code] };
removeChild: function removeChild() { [native code] };
appendChild: function appendChild() { [native code] };
hasChildNodes: function hasChildNodes() { [native code] };
cloneNode: function cloneNode() { [native code] };
normalize: function normalize() { [native code] };
isSupported: function isSupported() { [native code] };
lookupPrefix: function lookupPrefix() { [native code] };
isDefaultNamespace: function isDefaultNamespace() { [native code] };
lookupNamespaceURI: function lookupNamespaceURI() { [native code] };
ELEMENT_NODE: 1;
ATTRIBUTE_NODE: 2;
TEXT_NODE: 3;
CDATA_SECTION_NODE: 4;
ENTITY_REFERENCE_NODE: 5;
ENTITY_NODE: 6;
PROCESSING_INSTRUCTION_NODE: 7;
COMMENT_NODE: 8;
DOCUMENT_NODE: 9;
DOCUMENT_TYPE_NODE: 10;
DOCUMENT_FRAGMENT_NODE: 11;
NOTATION_NODE: 12;
DOCUMENT_POSITION_DISCONNECTED: 1;
DOCUMENT_POSITION_PRECEDING: 2;
DOCUMENT_POSITION_FOLLOWING: 4;
DOCUMENT_POSITION_CONTAINS: 8;
DOCUMENT_POSITION_CONTAINED_BY: 16;
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32;
isSameNode: function isSameNode() { [native code] };
isEqualNode: function isEqualNode() { [native code] };
compareDocumentPosition: function compareDocumentPosition() { [native code] };
contains: function contains() { [native code] };
addEventListener: function addEventListener() { [native code] };
removeEventListener: function removeEventListener() { [native code] };
dispatchEvent: function dispatchEvent() { [native code] };