web-dev-qa-db-ja.com

このXMLStarletクエリが機能しないのはなぜですか?

EBay開発者APIの検索結果から価格情報を解析する簡単なbashスクリプトを作成しようとしています。 「DetectiveComics700」のXML検索結果の例を次に示します。

<findItemsAdvancedResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2014-06-21T19:03:49.943Z</timestamp>
<searchResult count="1">
<item>
<itemId>301209856743</itemId>
<title>
DETECTIVE COMICS (1937 Series) #700 Near Mint Comics Book
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>77</categoryId>
<categoryName>Other</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs4.ebaystatic.com/m/mBYOI1SLUSGe0DL1FmHjdCw/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/DETECTIVE-COMICS-1937-Series-700-Near-Mint-Comics-Book-/301209856743?pt=US_Comic_Books
</viewItemURL>
<paymentMethod>Paypal</paymentMethod>
<paymentMethod>VisaMC</paymentMethod>
<paymentMethod>Discover</paymentMethod>
<autoPay>false</autoPay>
<location>USA</location>
<country>US</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">4.95</shippingServiceCost>
<shippingType>Flat</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>3</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">6.0</currentPrice>
<convertedCurrentPrice currencyId="USD">6.0</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P17DT7H31M1S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2014-06-09T02:34:50.000Z</startTime>
<endTime>2014-07-09T02:34:50.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<galleryPlusPictureURL>
http://galleryplus.ebayimg.com/ws/web/301209856743_1_0_1.jpg
</galleryPlusPictureURL>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>false</topRatedListing>
</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>1</entriesPerPage>
<totalPages>111</totalPages>
<totalEntries>111</totalEntries>
</paginationOutput>
<itemSearchURL>
http://www.ebay.com/sch/63/i.html?LH_TitleDesc=1&_nkw=detective+comics+700&_ddo=1&_ipg=1&_pgn=1
</itemSearchURL>
</findItemsAdvancedResponse>

基本的に、タイトル、価格、そしておそらく送料だけを解析したいと思います。

予備調査によると、これにはxmlstarletが賢明な選択ですが、機能していません(私は何か間違ったことをしているに違いないことを知っています)。

検索しようとすると、空白の結果が表示されます。

[foouser@foobox fooapp]# cat xmlsample | xmlstarlet sel -t -v "//title"
[foouser@foobox fooapp]#

[foouser@foobox fooapp]# xmlstarlet sel -t -v "//findItemsAdvancedResponse/searchResult/item/title" xmlsample
[foouser@foobox fooapp]#

私がどこに迷ったのかについて何か考えはありますか?

1
Mike B

手順を再現しようとすると、2つの問題が発生します。

  • _EntityRef: expecting ';'_

ソースドキュメントは_&_を使用しているようですが、_&amp;_を使用する必要があります。

_sed -i -e 's/&/&amp;/g' xmlresult_を使用して修正しました。

  • None of the XPaths matched; to match a node in the default namespace use '_' as the prefix (see section 5.1 in the manual).

セクション5.1 に続いて、XPathクエリ内に_-N services=http://www.ebay.com/marketplace/search/v1/services_を追加し、_services:_を配置しようとしましたが、今では何か便利なものが得られます。

_$ xmlstarlet sel -N services=http://www.ebay.com/marketplace/search/v1/services -t -v '//services:title' result.xml

DETECTIVE COMICS (1937 Series) #700 Near Mint Comics Book
_
1
Mikel