2014-03-03 53 views
1

我參與了一個正在從IE8移動到IE9的項目。我瞭解到,IE9及以上版本不再支持用於執行xPath查詢的selectNodes()。作爲迴應,我轉向Google的Wicked-Good-XPath,一個本地JavaScript xpath庫,以訪問Evaluate XPath函數。Wicked-Good-XPath評估xPathResult包含[Exception:TypeError]

我想對貌似執行XPath查詢的XML文檔:

<?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> 

因爲我要選擇任何/所有ADISResults節點,我的XPath查詢,取名字空間考慮,看起來像://*[local-name()='ADISResults']。該查詢似乎不是問題,因爲它在XPathTester處產生預期結果。

我的JavaScript調用妖獸就緒,XPath和它的評價函數如下:

wgxpath.install(); 
var xPathQuery = "//*[local-name()='ADISResults']"; 
var xpr = xdoc.evaluate(xPathQuery, xdoc, null, XPathResult.ANY_TYPE, null); 
var nl = xpr.singleNodeValue; 

但是,如果我運行上面的代碼,並檢查XPathResult,var xpr,我看[Exception: TypeError]許多變量的性質包括xpr.singleNodeValue。最終,我試圖將匹配的xml節點列表檢索到var nl

我在做什麼錯?

更新2014年3月4日:

進行更多的測試後,我認爲這個問題已經躺在我對我使用xdoc對象的假設。它被傳遞給一個jQuery AJAX對ASP.NET AJAX處理程序調用的success處理程序。在檢查xdoc對象的屬性時,它看起來像一個有效的XML文檔對象。 exaluate是否有一些我應該注意的特定屬性?

所有其他參數及其類型似乎與W3文檔一致,因此將xdoc對象作爲唯一的嫌疑人。

更新2 2014年3月4日:

確定。這必須在xdoc對象本身內部有些微妙之處。我已經生成了它的內容轉儲,希望它能幫助我們弄清楚這一點。

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] }; 

回答

0

這個本地名稱函數已修復XML文檔已在Wicked Good XPath中修復,但一般XML支持尚未得到保證。在它上面工作...

0

嘗試評估文檔。

wgxpath.install(); 
var xPathQuery = "//*[local-name()='ADISResults']"; 
var xpr = document.evaluate(xPathQuery, xdoc, null, XPathResult.ANY_TYPE, null); 
var nl = xpr.singleNodeValue;