肥皂 UI |如何在没有肥皂信封的 Soap UI 中解析 XML(响应)的节点

Soap UI | How to parse nodes of XML (response) in Soap UI which has no soap envelope

我们将如何解析下面响应中的第二个国家/地区节点,因为没有命名空间。它没有正确检测节点,通过使用 //*:Country,我得到 IN,这是响应中的第一个国家/地区节点

<Response xmlns="https://www.googleapis.com/books/v1/volumes">
   <items>
      <e>
         <accessInfo>
            <accessViewStatus>NONE</accessViewStatus>
            <country>IN</country>
            <embeddable>false</embeddable>
            <epub>
               <isAvailable>false</isAvailable>
            </epub>
            <pdf>
               <isAvailable>false</isAvailable>
            </pdf>
            <publicDomain>false</publicDomain>
            <quoteSharingAllowed>false</quoteSharingAllowed>
            <textToSpeechPermission>ALLOWED</textToSpeechPermission>
            <viewability>NO_PAGES</viewability>
            <webReaderLink>http://books.google.co.in/books/reader?id=8bkxV-WcLFoC&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api</webReaderLink>
         </accessInfo>
         <etag>iKsLXIuXjx8</etag>
         <id>8bkxV-WcLFoC</id>
         <kind>books#volume</kind>
         <saleInfo>
            <country>IN</country>
            <isEbook>false</isEbook>
            <saleability>NOT_FOR_SALE</saleability>
         </saleInfo>
         <searchInfo>
            <textSnippet>Beginning with an &amp;quot;Ant on an Apple&amp;quot;, illustrations, simple text, and a pesky fly who will not stay on his page introduce the letters of the alphabet.</textSnippet>
         </searchInfo>
         <selfLink>https://www.googleapis.com/books/v1/volumes/8bkxV-WcLFoC</selfLink>
         <volumeInfo>
            <allowAnonLogging>false</allowAnonLogging>
            <authors>
               <e>Bruno Munari</e>
            </authors>
            <canonicalVolumeLink>https://books.google.com/books/about/ABC.html?hl=&amp;id=8bkxV-WcLFoC</canonicalVolumeLink>
            <contentVersion>0.0.1.0.preview.0</contentVersion>
            <imageLinks>
               <smallThumbnail>http://books.google.com/books/content?id=8bkxV-WcLFoC&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;source=gbs_api</smallThumbnail>
               <thumbnail>http://books.google.com/books/content?id=8bkxV-WcLFoC&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;source=gbs_api</thumbnail>
            </imageLinks>
            <industryIdentifiers>
               <e>
                  <identifier>MINN:319510009151144</identifier>
                  <type>OTHER</type>
               </e>
            </industryIdentifiers>
            <infoLink>http://books.google.co.in/books?id=8bkxV-WcLFoC&amp;dq=abc&amp;hl=&amp;source=gbs_api</infoLink>
            <language>en</language>
            <maturityRating>NOT_MATURE</maturityRating>
            <panelizationSummary>
               <containsEpubBubbles>false</containsEpubBubbles>
               <containsImageBubbles>false</containsImageBubbles>
            </panelizationSummary>
            <previewLink>http://books.google.co.in/books?id=8bkxV-WcLFoC&amp;q=abc&amp;dq=abc&amp;hl=&amp;cd=1&amp;source=gbs_api</previewLink>
            <printType>BOOK</printType>
            <publishedDate>1960</publishedDate>
            <readingModes>
               <image>false</image>
               <text>false</text>
            </readingModes>
            <title>ABC.</title>
         </volumeInfo>
      </e>
      <e>
         <accessInfo>
            <accessViewStatus>NONE</accessViewStatus>
            <country>IN</country>
            <embeddable>false</embeddable>
            <epub>
               <isAvailable>false</isAvailable>
            </epub>
            <pdf>
               <isAvailable>false</isAvailable>
            </pdf>
            <publicDomain>false</publicDomain>
            <quoteSharingAllowed>false</quoteSharingAllowed>
            <textToSpeechPermission>ALLOWED</textToSpeechPermission>
            <viewability>NO_PAGES</viewability>
            <webReaderLink>http://books.google.co.in/books/reader?id=7s4WAQAAMAAJ&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api</webReaderLink>
         </accessInfo>
         <etag>miIPSeJ57M8</etag>
         <id>7s4WAQAAMAAJ</id>
         <kind>books#volume</kind>
         <saleInfo>
            <country>IN</country>
            <isEbook>false</isEbook>
            <saleability>NOT_FOR_SALE</saleability>
         </saleInfo>
         <selfLink>https://www.googleapis.com/books/v1/volumes/7s4WAQAAMAAJ</selfLink>
         <volumeInfo>
            <allowAnonLogging>false</allowAnonLogging>
            <authors>
               <e>Bruno Munari</e>
            </authors>
            <canonicalVolumeLink>https://books.google.com/books/about/ABC.html?hl=&amp;id=7s4WAQAAMAAJ</canonicalVolumeLink>
            <categories>
               <e>Juvenile Nonfiction</e>
            </categories>
            <contentVersion>preview-1.0.0</contentVersion>
            <imageLinks>
               <smallThumbnail>http://books.google.com/books/content?id=7s4WAQAAMAAJ&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;source=gbs_api</smallThumbnail>
               <thumbnail>http://books.google.com/books/content?id=7s4WAQAAMAAJ&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;source=gbs_api</thumbnail>
            </imageLinks>
            <industryIdentifiers>
               <e>
                  <identifier>UOM:49015000911801</identifier>
                  <type>OTHER</type>
               </e>
            </industryIdentifiers>
            <infoLink>http://books.google.co.in/books?id=7s4WAQAAMAAJ&amp;dq=abc&amp;hl=&amp;source=gbs_api</infoLink>
            <language>en</language>
            <maturityRating>NOT_MATURE</maturityRating>
            <previewLink>http://books.google.co.in/books?id=7s4WAQAAMAAJ&amp;q=abc&amp;dq=abc&amp;hl=&amp;cd=2&amp;source=gbs_api</previewLink>
            <printType>BOOK</printType>
            <publishedDate>1960</publishedDate>
            <readingModes>
               <image>false</image>
               <text>false</text>
            </readingModes>
            <title>ABC.</title>
         </volumeInfo>
      </e>
      <e>
         <accessInfo>
            <accessViewStatus>NONE</accessViewStatus>
            <country>IN</country>
            <embeddable>false</embeddable>
            <epub>
               <isAvailable>false</isAvailable>
            </epub>
            <pdf>
               <isAvailable>false</isAvailable>
            </pdf>
            <publicDomain>false</publicDomain>
            <quoteSharingAllowed>false</quoteSharingAllowed>
            <textToSpeechPermission>ALLOWED</textToSpeechPermission>
            <viewability>NO_PAGES</viewability>
            <webReaderLink>http://books.google.co.in/books/reader?id=Q6LsAAAAMAAJ&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api</webReaderLink>
         </accessInfo>
         <etag>wHyvfXqhLU8</etag>
         <id>Q6LsAAAAMAAJ</id>
         <kind>books#volume</kind>
         <saleInfo>
            <country>IN</country>
            <isEbook>false</isEbook>
            <saleability>NOT_FOR_SALE</saleability>
         </saleInfo>
         <searchInfo>
            <textSnippet>An intense examination of the effects of technology on literacy and language.</textSnippet>
         </searchInfo>
         <selfLink>https://www.googleapis.com/books/v1/volumes/Q6LsAAAAMAAJ</selfLink>
         <volumeInfo>
            <allowAnonLogging>false</allowAnonLogging>
            <authors>
               <e>Ivan Illich</e>
               <e>Barry Sanders</e>
            </authors>
            <canonicalVolumeLink>https://books.google.com/books/about/ABC.html?hl=&amp;id=Q6LsAAAAMAAJ</canonicalVolumeLink>
            <categories>
               <e>Information storage and retrieval systems</e>
            </categories>
            <contentVersion>1.1.1.0.preview.0</contentVersion>
            <description>An intense examination of the effects of technology on literacy and language. The authors argue that there is a phenomenon transforming modern culture--language is becoming part of a technology of "information systems" with an emphasis on control, rather than human exchange. As a result, all language is becoming debased.</description>
            <imageLinks>
               <smallThumbnail>http://books.google.com/books/content?id=Q6LsAAAAMAAJ&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;source=gbs_api</smallThumbnail>
               <thumbnail>http://books.google.com/books/content?id=Q6LsAAAAMAAJ&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;source=gbs_api</thumbnail>
            </imageLinks>
            <industryIdentifiers>
               <e>
                  <identifier>IND:30000036960999</identifier>
                  <type>OTHER</type>
               </e>
            </industryIdentifiers>
            <infoLink>http://books.google.co.in/books?id=Q6LsAAAAMAAJ&amp;dq=abc&amp;hl=&amp;source=gbs_api</infoLink>
            <language>en</language>
            <maturityRating>NOT_MATURE</maturityRating>
            <pageCount>166</pageCount>
            <previewLink>http://books.google.co.in/books?id=Q6LsAAAAMAAJ&amp;q=abc&amp;dq=abc&amp;hl=&amp;cd=3&amp;source=gbs_api</previewLink>
            <printType>BOOK</printType>
            <publishedDate>1988</publishedDate>
            <publisher>Marion Boyars Publishers</publisher>
            <readingModes>
               <image>false</image>
               <text>false</text>
            </readingModes>
            <subtitle>The Alphabetization of the Popular Mind</subtitle>
            <title>ABC</title>
         </volumeInfo>
      </e>
      <e>
         <accessInfo>
            <accessViewStatus>SAMPLE</accessViewStatus>
            <country>IN</country>
            <embeddable>true</embeddable>
            <epub>
               <isAvailable>false</isAvailable>
            </epub>
            <pdf>
               <isAvailable>false</isAvailable>
            </pdf>
            <publicDomain>false</publicDomain>
            <quoteSharingAllowed>false</quoteSharingAllowed>
            <textToSpeechPermission>ALLOWED</textToSpeechPermission>
            <viewability>PARTIAL</viewability>
            <webReaderLink>http://books.google.co.in/books/reader?id=f1vdiFRI52gC&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api</webReaderLink>
         </accessInfo>
         <etag>R8E127WkV8s</etag>
         <id>f1vdiFRI52gC</id>
         <kind>books#volume</kind>
         <saleInfo>
            <country>IN</country>
            <isEbook>false</isEbook>
            <saleability>NOT_FOR_SALE</saleability>
         </saleInfo>
         <searchInfo>
            <textSnippet>Includes 26 scenes which depict a Letterland character surrounded by objects beginning with the target sound. This children&amp;#39;s alphabet book helps children in promoting phonemic awareness and vocabulary development.</textSnippet>
         </searchInfo>
         <selfLink>https://www.googleapis.com/books/v1/volumes/f1vdiFRI52gC</selfLink>
         <volumeInfo>
            <allowAnonLogging>false</allowAnonLogging>
            <authors>
               <e>Lyn Wendon</e>
            </authors>
            <canonicalVolumeLink>https://books.google.com/books/about/ABC.html?hl=&amp;id=f1vdiFRI52gC</canonicalVolumeLink>
            <categories>
               <e>Alphabet</e>
            </categories>
            <contentVersion>0.2.0.0.preview.1</contentVersion>
            <description>Includes 26 scenes which depict a Letterland character surrounded by objects beginning with the target sound. This children's alphabet book helps children in promoting phonemic awareness and vocabulary development.</description>
            <imageLinks>
               <smallThumbnail>http://books.google.com/books/content?id=f1vdiFRI52gC&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;edge=curl&amp;source=gbs_api</smallThumbnail>
               <thumbnail>http://books.google.com/books/content?id=f1vdiFRI52gC&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;edge=curl&amp;source=gbs_api</thumbnail>
            </imageLinks>
            <industryIdentifiers>
               <e>
                  <identifier>9781862092211</identifier>
                  <type>ISBN_13</type>
               </e>
               <e>
                  <identifier>1862092214</identifier>
                  <type>ISBN_10</type>
               </e>
            </industryIdentifiers>
            <infoLink>http://books.google.co.in/books?id=f1vdiFRI52gC&amp;dq=abc&amp;hl=&amp;source=gbs_api</infoLink>
            <language>en</language>
            <maturityRating>NOT_MATURE</maturityRating>
            <pageCount>58</pageCount>
            <previewLink>http://books.google.co.in/books?id=f1vdiFRI52gC&amp;printsec=frontcover&amp;dq=abc&amp;hl=&amp;cd=4&amp;source=gbs_api</previewLink>
            <printType>BOOK</printType>
            <publishedDate>2003-04-01</publishedDate>
            <publisher>Letterland</publisher>
            <readingModes>
               <image>true</image>
               <text>false</text>
            </readingModes>
            <title>ABC</title>
         </volumeInfo>
      </e>

       </items>
       <kind>books#volumes</kind>
       <totalItems>2279</totalItems>
    </Response>

这里是从上面的 xml 字符串中提取 saleInfo/country 的例子。

Groovy 脚本

//Pass xml as string to parseText
def response = new XmlSlurper().parseText(xml)

//Below would display all country names from multiple `e` tags
log.info response.items.e.saleInfo.country

//Below would display country name from first `e` tag, increase the index to get the appropriate one in place of 0
log.info response.items.e[0].saleInfo.country

//Below to show the conditional country
//Get the country name if id is 8bkxV-WcLFoC
log.info response.items.e.'*'.find{ it.name() == 'id' && it == '8bkxV-WcLFoC' }.parent().saleInfo.country

类似于引用变量id,您可以更改/选择任何引用属性以使用不同的条件。

可以在线快速测试Demo