C#XPath什么都没回来

时间:2017-10-12 21:50:48

标签: c# xml xpath

我在c#中遇到了一些xpath查询问题。

给出xml:

Sub compare_cols()

    'Get the last row
    Dim Report As Worksheet
    Dim i As Integer, j As Integer
    Dim lastRow As Integer

    Set Report = Excel.ActiveSheet

    lastRow = Report.UsedRange.Rows.Count

    Application.ScreenUpdating = False

    For i = 2 To lastRow
        For j = 2 To lastRow
            If Report.Cells(i, 1).Value <> "" Then 'This will omit blank cells at the end (in the event that the column lengths are not equal.
                If InStr(1, Report.Cells(j, 2).Value, Report.Cells(i, 1).Value, vbTextCompare) > 0 Then

                    Report.Cells(i, 1).Interior.Color = RGB(255, 255, 255) 'White background
                    Report.Cells(i, 1).Font.Color = RGB(0, 0, 0) 'Black font color
                    Exit For
                Else
                    Report.Cells(i, 1).Interior.Color = RGB(156, 0, 6) 'Dark red background
                    Report.Cells(i, 1).Font.Color = RGB(255, 199, 206) 'Light red font color
                End If
            End If
        Next j
    Next i

    'Now I use the same code for the second column, and just switch the column numbers.
    For i = 2 To lastRow
        For j = 2 To lastRow
            If Report.Cells(i, 2).Value <> "" Then
                If InStr(1, Report.Cells(j, 1).Value, Report.Cells(i, 2).Value, vbTextCompare) > 0 Then
                    Report.Cells(i, 2).Interior.Color = RGB(255, 255, 255) 'White background
                    Report.Cells(i, 2).Font.Color = RGB(0, 0, 0) 'Black font color
                    Exit For
                Else
                    Report.Cells(i, 2).Interior.Color = RGB(156, 0, 6) 'Dark red background
                    Report.Cells(i, 2).Font.Color = RGB(255, 199, 206) 'Light red font color
                End If
            End If
        Next j
    Next i

Application.ScreenUpdating = True

End Sub

代码:

<BlahApi xsi:schemaLocation="https://api.blah.com/xsd/blah.xsd" Version="0.0.0.0" xmlns="Blah.Api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Status Code="0" Message="Success" NextID="0" NextCallTime="" />
    <ValidateCustomerAccountNumber>
        <Customer Name="Blah" ID="00000000-0000-0000-0000-000000000000" ApiToken="blah" ProfileId="blah" AdminEmail="blah@blah.com" CustomerEmail="" />
    </ValidateCustomerAccountNumber>
</BlahApi>

我希望能够获得Id的GUID。但它空洞。我已经尝试将其剥离到一个/并且我得到整个文档,但如果我尝试甚至做: var customerId = step1Response.XPathEvaluate("/BlahApi/ValidateCustomerAccountNumber/Customer/@ID"); 评估为空。

不确定我做错了什么。先谢谢。

0 个答案:

没有答案