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

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

eBay開発者API検索結果から価格情報を解析する簡単なbashスクリプトを作成しようとしています。以下は、「Detective Comics 700」の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

あなたのステップを再現しようとすると、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

おすすめ記事