XML XPath无法正常工作

时间:2011-10-17 12:38:04

标签: xml vb.net

我有以下两行代码:

Dim node As XmlNode = xDoc.SelectSingleNode("//response/agentStatusList/agentStatus/protectableVolumes/protectableVolume/metrics/lastWriteTime")
MsgBox(node.FirstChild.Value)

我希望获得lastWriteTime的第一个实例的值,它应该是2011-10-13T10:48:48.3833771-04:00,但代码只会弹出一个空字符串。很抱歉这篇文章很重要,但这里是整个XML文件供参考。任何人都可以看到为什么这不起作用,或者给我一个如何让它以其他方式工作的例子?

<responses xmlns="replayc.Xml.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <response>
    <commandName>GetAgentStatus</commandName>
    <errorMessage i:nil="true"/>
    <message>The GetSourceStatus is executed successfully.</message>
    <responseCode>0</responseCode>
    <stackTrace i:nil="true"/>
    <time>2011-10-13T10:48:48.3364607-04:00</time>
    <agentStatusList>
      <agentStatus>
        <allowAccessDuringRollbackFlag>true</allowAccessDuringRollbackFlag>
        <areDriversLoaded>true</areDriversLoaded>
        <backupWindowDuration>0</backupWindowDuration>
        <backupWindowStartTime>0001-01-01T00:00:00</backupWindowStartTime>
        <checksumCheckInProgress>false</checksumCheckInProgress>
        <checksumCheckJobSchedule>
          <recurrence>Nightly</recurrence>
          <weeklyDayOfWeek>Sunday</weeklyDayOfWeek>
        </checksumCheckJobSchedule>
        <clusterName/>
        <continuousSourceRollbackInfo>
          <enabled>false</enabled>
          <finishTime>0001-01-01T00:00:00</finishTime>
          <hotStandbyName/>
          <hotStandbyTargetIp/>
          <inProgress>false</inProgress>
          <lastReplicationTime>0001-01-01T00:00:00</lastReplicationTime>
          <percentDone>0</percentDone>
          <recoveryPointTimeStamp>0001-01-01T00:00:00</recoveryPointTimeStamp>
          <rollbackVolumeInfoMapDict/>
          <startTime>0001-01-01T00:00:00</startTime>
        </continuousSourceRollbackInfo>
        <currentRpExportStatus>
          <exportInProgress>false</exportInProgress>
          <exportStatusString>Off</exportStatusString>
          <finishTime>0001-01-01T00:00:00</finishTime>
          <isDifferentialExport>false</isDifferentialExport>
          <percentDone>0</percentDone>
          <recoveryPointTimeStamp>0001-01-01T00:00:00</recoveryPointTimeStamp>
          <startTime>0001-01-01T00:00:00</startTime>
        </currentRpExportStatus>
        <currentVmExportStatus>
          <exportInProgress>false</exportInProgress>
          <exportStatusString>Off</exportStatusString>
          <finishTime>0001-01-01T00:00:00</finishTime>
          <isDifferentialExport>false</isDifferentialExport>
          <percentDone>0</percentDone>
          <recoveryPointTimeStamp>0001-01-01T00:00:00</recoveryPointTimeStamp>
          <startTime>0001-01-01T00:00:00</startTime>
        </currentVmExportStatus>
        <edbsAndStatuses/>
        <enableLogTruncation>false</enableLogTruncation>
        <errorMsg/>
        <exchangeVersion>None</exchangeVersion>
        <forceDismountFlag>false</forceDismountFlag>
        <forceLogTruncation>false</forceLogTruncation>
        <haFeatures>ExchangeHaFeatureNone</haFeatures>
        <ipAddress>10.28.95.81</ipAddress>
        <logPath>e:\tevorepository\appassure</logPath>
        <name>appassure</name>
        <newestLastChanged>2011-10-13T10:48:48.2739055-04:00</newestLastChanged>
        <policyFlagsEdb>0</policyFlagsEdb>
        <policyFlagsSql>0</policyFlagsSql>
        <port>8004</port>
        <protectableVolumes>
          <protectableVolume>
            <isExchangeInstallVolume>false</isExchangeInstallVolume>
            <isSqlInstallVolume>false</isSqlInstallVolume>
            <metrics>
              <bytesTransfered>0</bytesTransfered>
              <lastWriteTime>2011-10-13T10:48:48.3833771-04:00</lastWriteTime>
              <totalBytesToTransfer>0</totalBytesToTransfer>
              <transferFinishTime>2011-10-13T10:48:48.3833771-04:00</transferFinishTime>
              <transferStartTime>2011-10-13T10:48:48.3833771-04:00</transferStartTime>
              <volumeName/>
            </metrics>
            <name i:nil="true"/>
            <sqlInstances/>
            <storageGroups/>
            <tevoDriverGuid>301fbed8-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuid>
            <tevoDriverGuidStr>301fbed8-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuidStr>
            <uniqueId>C:</uniqueId>
            <validForProtection>true</validForProtection>
          </protectableVolume>
          <protectableVolume>
            <isExchangeInstallVolume>false</isExchangeInstallVolume>
            <isSqlInstallVolume>false</isSqlInstallVolume>
            <metrics>
              <bytesTransfered>0</bytesTransfered>
              <lastWriteTime>2011-10-13T10:48:48.3833771-04:00</lastWriteTime>
              <totalBytesToTransfer>0</totalBytesToTransfer>
              <transferFinishTime>2011-10-13T10:48:48.3833771-04:00</transferFinishTime>
              <transferStartTime>2011-10-13T10:48:48.3833771-04:00</transferStartTime>
              <volumeName/>
            </metrics>
            <name i:nil="true"/>
            <sqlInstances/>
            <storageGroups/>
            <tevoDriverGuid>301fbed7-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuid>
            <tevoDriverGuidStr>301fbed7-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuidStr>
            <uniqueId>C:\Windows\SRPPartition</uniqueId>
            <validForProtection>true</validForProtection>
          </protectableVolume>
          <protectableVolume>
            <isExchangeInstallVolume>false</isExchangeInstallVolume>
            <isSqlInstallVolume>false</isSqlInstallVolume>
            <metrics>
              <bytesTransfered>0</bytesTransfered>
              <lastWriteTime>2011-10-13T10:48:48.3833771-04:00</lastWriteTime>
              <totalBytesToTransfer>0</totalBytesToTransfer>
              <transferFinishTime>2011-10-13T10:48:48.3833771-04:00</transferFinishTime>
              <transferStartTime>2011-10-13T10:48:48.3833771-04:00</transferStartTime>
              <volumeName/>
            </metrics>
            <name i:nil="true"/>
            <sqlInstances/>
            <storageGroups/>
            <tevoDriverGuid>301fbef5-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuid>
            <tevoDriverGuidStr>301fbef5-de11-11e0-8b0f-76c786fecbc5</tevoDriverGuidStr>
            <uniqueId>E:</uniqueId>
            <validForProtection>true</validForProtection>
          </protectableVolume>
          <protectableVolume>
            <isExchangeInstallVolume>false</isExchangeInstallVolume>
            <isSqlInstallVolume>false</isSqlInstallVolume>
            <metrics>
              <bytesTransfered>0</bytesTransfered>
              <lastWriteTime>2011-10-13T10:48:48.3833771-04:00</lastWriteTime>
              <totalBytesToTransfer>0</totalBytesToTransfer>
              <transferFinishTime>2011-10-13T10:48:48.3833771-04:00</transferFinishTime>
              <transferStartTime>2011-10-13T10:48:48.3833771-04:00</transferStartTime>
              <volumeName/>
            </metrics>
            <name i:nil="true"/>
            <sqlInstances/>
            <storageGroups/>
            <tevoDriverGuid>b690c188-e454-11e0-a2db-76c786fecbc5</tevoDriverGuid>
            <tevoDriverGuidStr>b690c188-e454-11e0-a2db-76c786fecbc5</tevoDriverGuidStr>
            <uniqueId>F:</uniqueId>
            <validForProtection>true</validForProtection>
          </protectableVolume>
        </protectableVolumes>
        <protectionGroups>
          <protectionGroup>
            <metrics>
              <protectableVolumeMetrics/>
              <transferStatus>Unknown</transferStatus>
            </metrics>
            <name>VolsWithInterval10080Minutes</name>
            <policyFlagsEdb>None</policyFlagsEdb>
            <policyFlagsSql>None</policyFlagsSql>
            <protectionInterval>P7D</protectionInterval>
            <volumes>
              <protectableVolumeContractLite>
                <uniqueId>C:</uniqueId>
              </protectableVolumeContractLite>
            </volumes>
          </protectionGroup>
        </protectionGroups>
        <reachable>true</reachable>
        <remountSqlFlag>true</remountSqlFlag>
        <remountStorageGroupsFlag>true</remountStorageGroupsFlag>
        <replicatedLogPath/>
        <role>Protected</role>
        <rollbackInProgress>false</rollbackInProgress>
        <rollupInProgress>false</rollupInProgress>
        <rpExportSettings>
          <enableExports>false</enableExports>
          <exportStartDateTime>0001-01-01T00:00:00</exportStartDateTime>
          <lastExportedRpTimeStamp>0001-01-01T00:00:00</lastExportedRpTimeStamp>
          <lastPollDateTime>0001-01-01T00:00:00</lastPollDateTime>
          <secondsTillNextPoll>PT0S</secondsTillNextPoll>
          <suspended>false</suspended>
          <timeBetweenUpdates>PT0S</timeBetweenUpdates>
        </rpExportSettings>
        <snapStartDateTime>0001-01-01T00:00:00</snapStartDateTime>
        <sourceLicenseInfo>
          <appMirrorDisplayName>High Availability</appMirrorDisplayName>
          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in</base64License>
          <companyName>LabTech</companyName>
          <compressionDisplayName>Compression</compressionDisplayName>
          <deduplicationDisplayName>Deduplication</deduplicationDisplayName>
          <dpmEditionDisplayName>DPM Edition (Only use for MailRetriever for DPM)</dpmEditionDisplayName>
          <exchangePackDisplayName>Replay for Exchange</exchangePackDisplayName>
          <expired>false</expired>
          <expiresInMilliseconds>4147753105</expiresInMilliseconds>
          <exportToFolderDisplayName>Rescue Image</exportToFolderDisplayName>
          <hyperVDisplayName>Replay for HyperV host</hyperVDisplayName>
          <invalidMsg/>
          <isAppMirror>true</isAppMirror>
          <isCompression>true</isCompression>
          <isDeduplication>true</isDeduplication>
          <isDpmEdition>false</isDpmEdition>
          <isExchangePack>true</isExchangePack>
          <isExportToFolder>true</isExportToFolder>
          <isHyperV>true</isHyperV>
          <isLiveReplay>true</isLiveReplay>
          <isOffsiteBackup>true</isOffsiteBackup>
          <isReplayMirror>true</isReplayMirror>
          <isRraEnabled>true</isRraEnabled>
          <isSQLPack>true</isSQLPack>
          <isSnapshotDailyEnabled>false</isSnapshotDailyEnabled>
          <isSnapshotHourly>false</isSnapshotHourly>
          <isTrial>false</isTrial>
          <licenseExpireDateTime>2012-08-04T23:59:59-04:00</licenseExpireDateTime>
          <licenseStartDateTime>2011-08-04T00:00:00-04:00</licenseStartDateTime>
          <licenseValid>true</licenseValid>
          <licenseeEmail>dmccallum@labtech.com</licenseeEmail>
          <licenseeName>Drew McCallum</licenseeName>
          <liveReplayDisplayName>Live Replay</liveReplayDisplayName>
          <numDataStoresLicensed>0</numDataStoresLicensed>
          <numMailboxesLicensed>0</numMailboxesLicensed>
          <offsiteBackupDisplayName>Replay Server Option - allows distributed cores</offsiteBackupDisplayName>
          <options xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:KeyValueOfstringstring>
              <a:Key>option-compression</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-deduplication</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-exchange</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-exportToFolder</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-hyperV</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-liveReplay</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-offsiteBackup</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-physicalStandby</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-recoverAnywhere</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-replayMirror</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
            <a:KeyValueOfstringstring>
              <a:Key>option-sql</a:Key>
              <a:Value/>
            </a:KeyValueOfstringstring>
          </options>
          <optionsDisplayNames xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:string>Compression</a:string>
            <a:string>Deduplication</a:string>
            <a:string>Replay for Exchange</a:string>
            <a:string>Rescue Image</a:string>
            <a:string>Replay for HyperV host</a:string>
            <a:string>Live Replay</a:string>
            <a:string>Replay Server Option - allows distributed cores</a:string>
            <a:string>High Availability</a:string>
            <a:string>Restore to Dissimilar Hardware Option</a:string>
            <a:string>Off-Site Replication Option</a:string>
            <a:string>Replay for SQL</a:string>
          </optionsDisplayNames>
          <orderDateTime>2011-08-04T16:46:13.5985502-04:00</orderDateTime>
          <orderNumber/>
          <products>
            <product>
              <displayName>Replay for Windows Server</displayName>
              <id>product-agent</id>
              <majorVersion>4</majorVersion>
              <minorVersion>5</minorVersion>
            </product>
            <product>
              <displayName>MailRetriever</displayName>
              <id>product-dsm</id>
              <majorVersion>4</majorVersion>
              <minorVersion>5</minorVersion>
            </product>
          </products>
          <replayMirrorDisplayName>Off-Site Replication Option</replayMirrorDisplayName>
          <rraEnabledDisplayName>Restore to Dissimilar Hardware Option</rraEnabledDisplayName>
          <snapshotDailyDisplayName>Daily Snapshots Only</snapshotDailyDisplayName>
          <snapshotHourlyDisplayName>Hourly Snapshots Only</snapshotHourlyDisplayName>
          <sqlPackDisplayName>Replay for SQL</sqlPackDisplayName>
          <thisProduct>
            <displayName>Replay for Windows Server</displayName>
            <id>product-agent</id>
            <majorVersion>4</majorVersion>
            <minorVersion>5</minorVersion>
          </thisProduct>
          <timeRemaining>-P296DT13H11M10.6322617S</timeRemaining>
          <trialDisplayName>Make Key a Trial</trialDisplayName>
        </sourceLicenseInfo>
        <sourceRollupPolicy>
          <daysToKeepAllSnaps>1</daysToKeepAllSnaps>
          <daysToKeepDailySnaps>7</daysToKeepDailySnaps>
          <daysToKeepHourlySnaps>2</daysToKeepHourlySnaps>
          <monthsToKeepMonthlySnaps>12</monthsToKeepMonthlySnaps>
          <schedule>
            <recurrence>Nightly</recurrence>
            <weeklyDayOfWeek>Sunday</weeklyDayOfWeek>
          </schedule>
          <weeksToKeepWeeklySnaps>5</weeksToKeepWeeklySnaps>
        </sourceRollupPolicy>
        <sqlInstances/>
        <sqlVersion>None</sqlVersion>
        <statusInfoAvailable>true</statusInfoAvailable>
        <storageGroups/>
        <totalPhysicalRamBytes>1069142016</totalPhysicalRamBytes>
        <version>4.6.1.34188</version>
        <volsAndStatuses/>
        <wallClockDateTime>2011-10-13T10:48:44.6144263-04:00</wallClockDateTime>
      </agentStatus>
    </agentStatusList>
  </response>
</responses>

2 个答案:

答案 0 :(得分:3)

您的节点都在非空命名空间中,并且您没有在XPath查询中指定此命名空间。这就是为什么它一无所获。

示例:

Dim resolver = New XmlNamespaceManager(xDoc.NameTable)
resolver.AddNamespace("c", "replayc.Xml.Contracts")
Dim node = xDoc.SelectSingleNode("//c:response/c:agentStatusList/c:agentStatus/c:protectableVolumes/c:protectableVolume/c:metrics/c:lastWriteTime", resolver)

您在XPath文本中使用的名称空间前缀完全是任意的,只要它映射到的URI与文档中的名称空间URI匹配。

答案 1 :(得分:0)

您的XML文档具有默认命名空间(xmlns="replayc.Xml.Contracts")。

您必须在发出XPath查询之前注册该命名空间,当然您必须在查询本身中使用该命名空间。

Dim nsMgr As New XmlNamespaceManager(xDoc)
nsMgr.AddNamespace("c", "replayc.Xml.Contracts")

Dim xpath As String = "//c:response/c:agentStatusList/c:agentStatus/c:protectableVolumes/c:protectableVolume/c:metrics/c:lastWriteTime"
Dim node As XmlNode = xDoc.SelectSingleNode(xpath, nsMgr)

MsgBox(node.FirstChild.Value)