我正在尝试开发一个标记(在这种情况下是运行在较大VBScript内部的代码片段),它从由第三方软件提供给Word插件的XML中返回信息,并使用书签提供参数给标记。
这里是正在发生的事情:
XmlDoc.SetProperty "SelectionLanguage", "XPath"
ReturnData = vbNullString
Public Function GetParameterXml()
GetParameterXml = _
"<Parameters>" & _
"<Parameter Value='Last_Hearing' Code='L' Description='Last_Hearing' Type='Combo'>" & _
"<Options>" & _
"<Option Code='' Description='True' Value='True' />" & _
"<Option Code='' Description='False' Value='False' />" & _
"</Options>" & _
"</Parameter>" & _
"</Parameters>"
End Function
Dim oNode : Set oNode = XmlDoc.SelectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting/CourtroomMinutes/Comment")
Dim lastHearing : Set lastHearing = Parameters.Item( BookMark, "Last_Hearing" )
If IsNull(lastHearing) Then
lastHearing = False
End If
stop
If lastHearing.Value = "True" Then
Dim dateNodes : Set dateNodes = XmlDoc.SelectNodes("/Record/CelloXml/Integration/Case/Hearing/Setting/HearingDate")
Dim mostRecentHearingDate
Dim dateNode
Dim todaysDate
todaysDate = Date
Dim dateList : Set dateList = CreateObject("System.Collections.ArrayList")
For Each dateNode In dateNodes
dateList.Add CDate(dateNode.Text)
Next
dateList.Sort()
Dim tempDate
For Each tempDate In dateList
If tempDate < todaysDate Then
mostRecentHearingDate = tempDate
End If
Next
mostRecentHearingDate = CStr(mostRecentHearingDate)
Set oNode = XmlDoc.selectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting[HearingDate/text()='" & mostRecentHearingDate & "']/CourtroomMinutes/Comment")
End If
If Not oNode Is Nothing Then
ReturnData = oNode.text
Else
ReturnData = vbNullString
End If
一切都按照我的意愿运行,直到...
Set oNode = XmlDoc.selectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting[HearingDate/text()='" & mostRecentHearingDate & "']/CourtroomMinutes/Comment")
我需要dateList
保存日期(或日期字面量),因为我认为如果我尝试将日期作为字符串而不是实际日期进行排序,那么排序结果会很糟糕,所以我将节点中的文本转换为日期(或日期字面量)并将其添加到dateList
中。
当我完成所有计算后,我需要一个字符串在我的XPath中运行,如果我将日期(作为字符串{08/05/2014})硬编码到XPath查询中,它可以正常工作,但当我使用CStr
将mostRecentHearingDate
转换为字符串时,oNode
被设置为无效。
该节点存在并且包含数据
所以,
- 为什么会发生这种情况?
- 如何使它按照我想象中的方式运行?
#
)移除并替换为空,但那也没有起作用。 - MalachiReplace(mostRecentHearingDate, "#", "")
也会去掉零。你的答案是正确的,解决了这个问题。我看到了正确的日期,没有注意到缺少的零。谢谢。 - MalachiFormatDateTime
和vbShortDate
代替CStr()
,但这取决于你的区域设置。FormatDateTime
- oracle certified professional