黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

XmlDocument的selectSingleNode方法,總支持Xpat

系統(tǒng) 2254 0

問題
??? 今天在修改程序的一個(gè)BUG時(shí),竟然發(fā)現(xiàn)selectSingleNode方法不支持contains Xpath函數(shù),感到很奇怪。在網(wǎng)上和MSDN也沒有發(fā)現(xiàn)官方言論表明selectSingleNode不支持contains 函數(shù)。
當(dāng)時(shí)我的情景大概是這樣的:

1、Xml文檔的結(jié)構(gòu)

<? 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.我的實(shí)現(xiàn)。
??? 我希望通過代碼找到expressionContext不等于T_SUBTITLE/ICHANNELNUM,并且xsf:suExpression中包含字符串"ICHANNELNUM"的節(jié)點(diǎn)。我書寫了以下代碼來實(shí)現(xiàn):

// 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 + " ')] " );

?? 這時(shí)IE報(bào)出錯(cuò)誤:contains是未實(shí)現(xiàn)的方法!。這下我就暈了,明明在Xpath的參考手冊,MSDN上都寫著contains是支持的方法。

原因

? 難道真的不支持?
?查閱MSDN我發(fā)現(xiàn)還有以下Xpath函數(shù):

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不支持嗎?其他函數(shù)呢?為了證實(shí)我的想法,我嘗試了上述所有函數(shù),IE都報(bào)出同樣的錯(cuò)誤,原來都不支持!

原來只有4.0版本的支持
??? 我發(fā)現(xiàn)這些Xpath函數(shù)的說明在MSXML 4.0 SDK下,難道只有4.0版本支持?于是我把代碼進(jìn)行了修改:

// 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 + " ')] " );

????? 運(yùn)行程序,竟然不再拋出contains函數(shù)不支持的錯(cuò)誤了,但是出現(xiàn)另外一個(gè)錯(cuò)誤,xsf是未定義的前綴。對,應(yīng)該是沒有聲明名稱空間。我對代碼再次進(jìn)行了修改:

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 + " ')] " );

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

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

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

// 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函數(shù)嗎?


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論