【发布时间】:2014-01-09 11:58:38
【问题描述】:
我有以下 XML 代码:
<OrganisationInfo>
<NetworkList>
<Network>
<NetworkData>
<RoutingInfoSection>
<ChangeHistory>
<ChangeHistoryItem>
<Date>2013-06-04</Date>
<Description>BLABLABLA</Description>
</ChangeHistoryItem>
<ChangeHistoryItem>
<Date>2013-05-21</Date>
<Description>BLABLABLA</Description>
</ChangeHistoryItem>
</ChangeHistory>
</RoutingInfoSection>
</NetworkData>
</Network>
</NetworkList>
</OrganisationInfo>
到目前为止,我已经完成了一个 VBScript,它能够读取目录中的 xml 文件,获取一些节点值并将它们保存到 txt 文件中,但我不想获取“日期”节点中的所有值...我下面的函数将分配给 Operadora 和“Alteracao”的每个值保存在“Operadora &”;“&Alteracao”上,但是如何更改我的代码以便它只获取存在的最新日期?
我的意思是:一些 XML 带有最新的 Date 在第一位,其中一些在最后,还有一些在中间......我怎么能得到最新的,无论它在哪里?
我想要最近一年的日期(2014,如果有日期为 2014、2013、2012、2011...),最近一个月(12,如果有月份 12、06、08 或11,例如)等等,最近一天。
一直遵循我的代码:
Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0") 'Msxml2.DOMDocument / Microsoft.XMLDOM
xmlDoc.Async = "False"
xmlDoc.setProperty "SelectionLanguage", "XPath"
Function ExportaDados
For Each f In fso.GetFolder("C:\Users\f8057612\Desktop\Bancos\Script_Operadoras").Files
If LCase(fso.GetExtensionName(f)) = "xml" Then
xmlDoc.Load f.Path
If xmlDoc.ParseError = 0 Then
For Each OrganisationInfo In xmlDoc.SelectNodes("//OrganisationInfo/OrganisationName")
Operadora = OrganisationInfo.Text
temp = ""
For Each Alteracao_Dir In xmlDoc.SelectNodes("//RoutingInfoSection/ChangeHistory/ChangeHistoryItem/Date")
If Alteracao_Dir.Text <> temp Then
temp = Alteracao_Dir.Text
Alteracao = Alteracao_Dir.Text
objetoSaida_Alteracao.WriteLine Operadora & ";" & Alteracao
End If
temp = Alteracao_Dir.Text
Next
Next
WScript.Echo "Parsing error: '" & f.Path & "': " & xmlDoc.ParseError.Reason
End If
End If
Next
End Function
【问题讨论】: