亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

XmlDocument的selectSingleNode方法,總支持Xpat

系統 1828 0

問題
??? 今天在修改程序的一個BUG時,竟然發現selectSingleNode方法不支持contains Xpath函數,感到很奇怪。在網上和MSDN也沒有發現官方言論表明selectSingleNode不支持contains 函數。
當時我的情景大概是這樣的:

1、Xml文檔的結構

<? xml?version="1.0"? ?> ?
< xsf:xDocumentClass? xmlns:xsf ="http://schemas.microsoft.com/office/infopath/2003/solutionDefinition" >
< xsf:errorCondition? expressionContext ="T_SUBTITLE/ICHANNELNUM" >
??
< xsf:subExpression? > Xpath_getSigleNodeValue("T_SUBTITLE/ICHANNELNUM","../ITIMESUSAGE") < 1 </xsf:subExpression > ?
??
</ xsf:errorCondition >
-?
< xsf:errorCondition? expressionContext ="T_DESCAUTHORIZE/ITIMESUSAGE" >
??
< xsf:subExpression > Xpath_getSigleNodeValue("T_DESCAUTHORIZE/ITIMESUSAGE","../ICHANNELNUM") < 1
</xsf:subExpression > ?
??
</ xsf:errorCondition >
</ xsf:xDocumentClass >

2.我的實現。
??? 我希望通過代碼找到expressionContext不等于T_SUBTITLE/ICHANNELNUM,并且xsf:suExpression中包含字符串"ICHANNELNUM"的節點。我書寫了以下代碼來實現:

// aObjView_Xsf是存儲上述Xml的文檔對象
var ?aObjView_Xsf? = new ?ActiveXObject('MSXML2.DOMDocument');
aObjView_Xsf.load(
" test.xml " );
var ?objerrorConditions? = ?aObjView_Xsf.selectSingleNode( " xsf:xDocumentClass/xsf:customValidation/xsf:errorCondition[@expressionContext!=' " + strBinding + ? " '?and?contains(xsf:subExpression,' " + fieldName + " ')] " );

?? 這時IE報出錯誤:contains是未實現的方法!。這下我就暈了,明明在Xpath的參考手冊,MSDN上都寫著contains是支持的方法。

原因

? 難道真的不支持?
?查閱MSDN我發現還有以下Xpath函數:

Microsoft XML Core Services (MSXML) 4.0 - XPath Reference

String Functions

concat Returns the concatenation of the arguments.
contains Returns true if the first argument string contains the second argument string; otherwise returns false.
normalize-space Returns the argument string with the white space stripped.
starts-with Returns true if the first argument string starts with the second argument string; otherwise returns false.
string Converts an object to a string.
string-length Returns the number of characters in the string.
substring Returns the substring of the first argument starting at the position specified in the second argument and the length specified in the third argument.
substring-after Returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string.
substring-before Returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string.
translate Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.

?? 難道就只有contains不支持嗎?其他函數呢?為了證實我的想法,我嘗試了上述所有函數,IE都報出同樣的錯誤,原來都不支持!

原來只有4.0版本的支持
??? 我發現這些Xpath函數的說明在MSXML 4.0 SDK下,難道只有4.0版本支持?于是我把代碼進行了修改:

// aObjView_Xsf是存儲上述Xml的文檔對象
var ?aObjView_Xsf? = new ?ActiveXObject('Msxml2.DOMDocument. 4.0 ');
aObjView_Xsf.load(
" test.xml " );
var ?objerrorConditions? = ?aObjView_Xsf.selectSingleNode( " xsf:xDocumentClass/xsf:customValidation/xsf:errorCondition[@expressionContext!=' " + strBinding + ? " '?and?contains(xsf:subExpression,' " + fieldName + " ')] " );

????? 運行程序,竟然不再拋出contains函數不支持的錯誤了,但是出現另外一個錯誤,xsf是未定義的前綴。對,應該是沒有聲明名稱空間。我對代碼再次進行了修改:

var ?aObjView_Xsf? = new ?ActiveXObject('Msxml2.DOMDocument. 4.0 ');
aObjView_Xsf.load(
" test.xml " );
aObjView_Xsf.setProperty(
" SelectionNamespaces " , " xmlns:xsf='http://schemas.microsoft.com/office/infopath/2003/solutionDefinition' " );
var ?objerrorConditions? = ?aObjView_Xsf.selectSingleNode( " xsf:xDocumentClass/xsf:customValidation/xsf:errorCondition[@expressionContext!=' " + strBinding + ? " '?and?contains(xsf:subExpression,' " + fieldName + " ')] " );

??? 運行程序,測試通過!于是我下了這樣一個結論:只有Msxml2.DOMDocument.4.0以上版本才支持這些Xpath函數。但是這個結論對嗎?我自己也不敢確定。

不只Msxml2.DOMDocument 4.0以上版本支持contains等Xpath函數

???? 我進一步的查找了一些資料,都沒有信息表明Msxml2.DOMDocument 2.0不支持這些Xpath函數。到底Msxml2.DOMDocument 2.0、Msxml2.DOMDocument 3.0為什么支持類似等于、不等于、大于這樣的操作符,而無法識別contains這樣的函數呢?直到我發現了這個方法:setProperty("SelectionLanguage", "XPath")。這時我恍然大悟,原來4.0以下版本的Msxml2.DOMDocument默認用類似正則匹配的方法來進行節點選取的,而4.0及以上版本默認采用Xpath作為默認的選擇語言。
??? 我采用Msxml2.DOMDocument 2.0,將代碼做以下修改也是可以正常運行的:

// aObjView_Xsf是存儲上述Xml的文檔對象
var ?aObjView_Xsf? = new ?ActiveXObject('MSXML2.DOMDocument');
aObjView_Xsf.setProperty(
" SelectionLanguage " ,? " XPath " );
aObjView_Xsf.setProperty(
" SelectionNamespaces " , " xmlns:xsf='http://schemas.microsoft.com/office/infopath/2003/solutionDefinition' " );
aObjView_Xsf.load(
" test.xml " );
var ?objerrorConditions? = ?aObjView_Xsf.selectSingleNode( " xsf:xDocumentClass/xsf:customValidation/xsf:errorCondition[@expressionContext!=' " + strBinding + ? " '?and?contains(xsf:subExpression,' " + fieldName + " ')] " );




?

XmlDocument的selectSingleNode方法,總支持Xpath函數嗎?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 四虎在线观看网址 | 性生活国产| 国产美女在线观看 | 亚洲毛片在线免费观看 | 五月婷综合 | 国产九九热 | 天天射天天搞 | 日韩欧美在线观看视频一区二区 | 久久精品国产精品亚洲精品 | 伊人久久一本大道 | 最新亚洲情黄在线网站 | 老司机午夜影院 | 视频三区精品中文字幕 | 亚洲欧美日韩人成 | 99青青 | 国产精品最新 | 久久网页 | 婷婷亚洲综合 | 超级97碰碰碰碰久久久久最新 | 蝌蚪久久 | 亚洲国产99在线精品一区二区 | 深夜福利免费在线观看 | 国产乱人伦偷精品视频不卡 | 狼狼色丁香久久女婷婷综合 | 久久黄色免费视频 | 91久久精品| 久久精品操 | 亚洲成人黄色在线 | 中文字幕一区二区三 | 99久久精品费精品国产一区二 | 农村苗族一级特黄a大片 | 自拍中文字幕 | 在线免费观看国产精品 | 九九久久精品国产 | 9久re在线观看视频精品 | 日韩在线看片 | 99热1| 久久国产精品老人性 | 国产亚洲精品自在久久77 | 欧美激情免费看 | jizzjizz美女 |