空手道:匹配xml中的重复元素

时间:2019-03-29 11:18:56

标签: karate

我正在尝试匹配xml中的重复元素以使模式空手道。

XML消息

    Dim Searchstring As String
    Searchstring = RichTextBox1.Text
    Dim SearchStringPlus = Regex.Replace(Searchstring, "\s+", "+")
    Dim SearchHTML As String
    Dim WebClient1 As New Net.WebClient
    SearchHTML = WebClient1.DownloadString("https://www.imdb.com/find?ref_=nv_sr_fn&q=" & SearchStringPlus & "&s=tt")
    Dim SearchIndex As String = "<td class=""primary_photo""> <a href=""/title/tt"
    Dim iSearch As System.IO.StreamWriter
    iSearch = My.Computer.FileSystem.OpenTextFileWriter("iSearch.txt", False)
    iSearch.WriteLine(SearchHTML)
    iSearch.Close()
    Dim SearchHTMLR As String
    SearchHTMLR = IO.File.ReadAllLines("iSearch.txt").FirstOrDefault(Function(x) x.Contains(SearchIndex))
    Dim titles As String
    titles = GetStringBetween(SearchHTMLR, "<a href=""/title/", "/?ref_=fn_tt_tt_1")
    MessageBox.Show(titles)

我想将每个空手道模式都与之匹配

* def xmlResponse =
"""
<Envelope>
   <Header/>
   <Body>
      <Response>
         <Customer>
            <keys>
               <primaryKey>1111111</primaryKey>
            </keys>
            <simplePay>false</simplePay>
         </Customer>
         <serviceGroupList>
            <serviceGroup>
               <name>XXXX</name>
               <count>1</count>
               <parentName>DDDDD</parentName>
               <pendingCount>0</pendingCount>
               <pendingHWSum>0.00</pendingHWSum>
            </serviceGroup>
            <serviceGroup>
               <name>ZZZZZ</name>
               <count>0</count>
               <parentName/>
               <pendingCount>3</pendingCount>
               <pendingHWSum>399.00</pendingHWSum>
            </serviceGroup>
         </serviceGroupList>
      </Response>
   </Body>
</Envelope>
"""

这就是我尝试的方式

 Given def serviceGroupItem =
  """
    <serviceGroup>
               <name>##string</name>
               <count>##string</count>
               <parentName>##string</parentName>
               <pendingCount>##string</pendingCount>
               <pendingHWSum>##string</pendingHWSum>
            </serviceGroup>
  """

但是它不起作用。知道如何使它起作用

1 个答案:

答案 0 :(得分:2)

您必须匹配每个serviceGroup。

* xml serviceGroupListItems = get xmlResponse //serviceGroupList
* match each serviceGroupListItems.serviceGroupList.serviceGroup == serviceGroupItem.serviceGroup