Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date oNode设置为Nothing,但是为什么,我如何修复它?_Date_Datetime_Xpath_Vbscript_Msxml - Fatal编程技术网

Date oNode设置为Nothing,但是为什么,我如何修复它?

Date oNode设置为Nothing,但是为什么,我如何修复它?,date,datetime,xpath,vbscript,msxml,Date,Datetime,Xpath,Vbscript,Msxml,我正在尝试开发一个令牌(在本例中是在更大的VBScript中运行的一段代码),该令牌使用书签向word插件返回由第三方软件提供的XML信息,以向令牌提供参数 这就是发生的事情 XmlDoc.SetProperty "SelectionLanguage", "XPath" ReturnData = vbNullString Public Function GetParameterXml() GetParameterXml = _ "<Parameters>" &am

我正在尝试开发一个令牌(在本例中是在更大的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
我需要
dateList
来保存日期(或日期文字),因为我假设如果我尝试将日期作为字符串而不是实际日期进行排序,则会得到错误的排序,因此我将节点中的文本转换为日期(或日期文字),并将其添加到
dateList

当我完成所有的计算后,我需要一个字符串在XPath中运行,如果我将日期(作为字符串{08/05/2014})硬编码到XPath查询中,它会工作,但是当我使用
CStr
mostRecentHearingDate
转换为字符串时,
oNode
设置为空

节点存在并保存数据

所以

  • 为什么会这样
  • 我如何让它以我认为应该的方式运行
如果你这样做

dim mostRecentHearingDate
mostRecentHearingDate = CDate("08/05/2014")
mostRecentHearingDate = CStr(mostRecentHearingDate)
mostRecentHearingDate=“2014年5月8日”不是“2014年5月8日”,它删除了前面的“0”

试一试

这就产生了

08/05/2014

天哪!真不敢相信我没看到。除了那个长而难看的字符串之外,没有其他方法可以解决这个问题吗?可能有更有效的方法,但基本上你必须用前导“0”来填充我之前尝试过的内容,只是删除日期文字符号(
#
)并将其替换为零,但这不起作用。你没有提供xml示例,也许这将有助于进行
替换(大多数情况下,”#“,”)
也会去除零。您的答案是正确的,解决了问题。我看到了正确的日期,没有注意到丢失的零。非常感谢。
mostRecentHearingDate = Right("0"&DatePart("m",mostRecentHearingDate),2) & "/" & Right("0"&DatePart("d",mostRecentHearingDate),2) &  "/" & DatePart("YYYY",mostRecentHearingDate)
08/05/2014