Kai*_*ngh 0 xml vbscript xpath msxml
我试图使用XPath实现不区分大小写的搜索.我已经提到了如何在xquery中执行不区分大小写的属性选择器,因此请在标记为重复之前进行检查.我使用Lcase将我的variable(L_search)转换为小写和小写函数.
我原来区分大小写的XPath表达式是:
XPath = "//*[contains(., '"& search &"')]/ancestor-or-self::*/*[local-name()='home' and @locale='en']"
Run Code Online (Sandbox Code Playgroud)
我尝试过很多组合,比如:
XPath = "//*lower-case([contains(., '"& L_search &"')])/ancestor-or-self::*/*[local-name()='home' and @locale='en']"
XPath = "//*[contains(lower-case(.), '"& L_search &"')])/ancestor-or-self::*/*[local-name()='home' and @locale='en']"
Run Code Online (Sandbox Code Playgroud)
但他们都没有产生结果.
这是我正在运行的代码:
Sub ProcessFolder(FolderPath)
On Error Resume Next
Set fldr = fso.GetFolder(FolderPath)
Set Fls = fldr.files
For Each thing in Fls
sFSpec = FSO.GetAbsolutePathName(thing)
objMSXML.async = True
objMSXML.load sFSpec
If 0 = objMSXML.parseError Then
Dim sXPath : sXPath = "//*[contains(., '"& search &"')]/ancestor-or-self::*/*[local-name()='name' and @locale='en']"
Dim querySubject : Set querySubject = objMSXML.selectSingleNode(sXPath)
Set p = document.createElement("p")
p.innerText = thing.Path
document.body.appendChild p
If querySubject Is Nothing Then
MsgBox sXPath, "failed"
Run Code Online (Sandbox Code Playgroud)
VBScript仅支持XPath 1.0而不支持XQuery,因此首先编辑您的问题标题.
在XPath 1.0中,该translate()函数用于不区分大小写.
//*[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') , search)]/ancestor-or-self::*/*[local-name()='home' and @locale='en']
Run Code Online (Sandbox Code Playgroud)
搜索= Lcase(V_SAEARCH)
它会很完美.无需在变量周围使用引号.
另一种写这个的方法是: -
//*[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') , translate('" & search & "', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]/ancestor-or-self::*/*[local-name()='home' and @locale='en']
Run Code Online (Sandbox Code Playgroud)
这里搜索变量正在XPath中翻译.