2017-04-19 34 views
0

由於沒有名稱空間,我們將如何解析下面的響應中的第二個國家/地區節點。它不正確檢測到的節點,並通過使用// *:國家,我正在其中在響應肥皂UI |如何解析Soap UI中沒有soap信封的XML(響應)節點

<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> 
+0

是否有可能爲後期完全反應?順便說一句,你有沒有任何已知的參考價值來獲得鏈接的國家。因爲它似乎有多個'item'元素。 – Rao

+0

順便說一句,「non soapui response」是什麼意思? – Rao

+0

你爲什麼在你的問題中使用blockquote? – MetaColon

回答

1

這裏的第一個國家節點是從上面的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

+0

它像一個魅力,感謝您的幫助。 非常感謝 – vdrulerz

+0

@vdrulerz,很高興知道它的幫助。 – Rao