gpt4 book ai didi

java - 解析来自 YQL 的 XML 响应的常用库

转载 作者:行者123 更新时间:2023-12-01 16:01:38 25 4
gpt4 key购买 nike

目前我尝试通过YQL获取数据。

select * from yahoo.finance.quotes where symbol in ("BP")

我将得到 XML 响应。

我想知道,在我的 Java 应用程序中,是否有任何常用的库可以用来解析 XML?

或者我应该要求响应采用 JSON 格式吗?然后用JSONObject来解析呢?哪一个会更容易?

这是 XML 响应。

<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="1" yahoo:created="2010-09-16T05:00:13Z" yahoo:lang="en-US">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url execution-time="2" proxy="DEFAULT"><![CDATA[http://datatables.org/alltables.env]]></url>
<url execution-time="2" proxy="DEFAULT"><![CDATA[http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml]]></url>
<url execution-time="9" proxy="DEFAULT"><![CDATA[http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=BP]]></url>
<url execution-time="11"><![CDATA[select * from csv where url=@url and columns='Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,Change&PercentChange,Change,Commission,ChangeRealtime,AfterHoursChangeRealtime,DividendShare,LastTradeDate,TradeDate,EarningsShare,ErrorIndicationreturnedforsymbolchangedinvalid,EPSEstimateCurrentYear,EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,HoldingsGainPercent,AnnualizedGain,HoldingsGain,HoldingsGainPercentRealtime,HoldingsGainRealtime,MoreInfo,OrderBookRealtime,MarketCapitalization,MarketCapRealtime,EBITDA,ChangeFromYearLow,PercentChangeFromYearLow,LastTradeRealtimeWithTime,ChangePercentRealtime,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime,LastTradePriceOnly,HighLimit,LowLimit,DaysRange,DaysRangeRealtime,FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,ChangeFromFiftydayMovingAverage,PercentChangeFromFiftydayMovingAverage,Name,Notes,Open,PreviousClose,PricePaid,ChangeinPercent,PriceSales,PriceBook,ExDividendDate,PERatio,DividendPayDate,PERatioRealtime,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,Symbol,SharesOwned,ShortRatio,LastTradeTime,TickerTrend,OneyrTargetPrice,Volume,HoldingsValue,HoldingsValueRealtime,YearRange,DaysValueChange,DaysValueChangeRealtime,StockExchange,DividendYield']]></url>
<javascript execution-time="26" instructions-used="67513" table-name="yahoo.finance.quotes"/>
<user-time>48</user-time>
<service-time>13</service-time>
<build-version>9128</build-version>
</diagnostics>
<results>
<quote symbol="BP">
<Ask/>
<AverageDailyVolume>38597700</AverageDailyVolume>
<Bid/>
<AskRealtime>38.25</AskRealtime>
<BidRealtime>38.15</BidRealtime>
<BookValue>27.294</BookValue>
<Change_PercentChange>-0.34 - -0.88%</Change_PercentChange>
<Change>-0.34</Change>
<Commission/>
<ChangeRealtime>-0.34</ChangeRealtime>
<AfterHoursChangeRealtime>N/A - N/A</AfterHoursChangeRealtime>
<DividendShare>2.52</DividendShare>
<LastTradeDate>9/15/2010</LastTradeDate>
<TradeDate/>
<EarningsShare>-0.462</EarningsShare>
<ErrorIndicationreturnedforsymbolchangedinvalid>N/A</ErrorIndicationreturnedforsymbolchangedinvalid>
<EPSEstimateCurrentYear>6.14</EPSEstimateCurrentYear>
<EPSEstimateNextYear>6.38</EPSEstimateNextYear>
<EPSEstimateNextQuarter>1.38</EPSEstimateNextQuarter>
<DaysLow>37.77</DaysLow>
<DaysHigh>38.25</DaysHigh>
<YearLow>26.75</YearLow>
<YearHigh>62.38</YearHigh>
<HoldingsGainPercent>- - -</HoldingsGainPercent>
<AnnualizedGain>-</AnnualizedGain>
<HoldingsGain/>
<HoldingsGainPercentRealtime>N/A - N/A</HoldingsGainPercentRealtime>
<HoldingsGainRealtime/>
<MoreInfo>cnprmIed</MoreInfo>
<OrderBookRealtime>N/A</OrderBookRealtime>
<MarketCapitalization>119.6B</MarketCapitalization>
<MarketCapRealtime/>
<EBITDA>7.272B</EBITDA>
<ChangeFromYearLow>+11.43</ChangeFromYearLow>
<PercentChangeFromYearLow>+42.73%</PercentChangeFromYearLow>
<LastTradeRealtimeWithTime>N/A - &lt;b&gt;38.18&lt;/b&gt;</LastTradeRealtimeWithTime>
<ChangePercentRealtime>N/A - -0.88%</ChangePercentRealtime>
<ChangeFromYearHigh>-24.20</ChangeFromYearHigh>
<PercebtChangeFromYearHigh>-38.79%</PercebtChangeFromYearHigh>
<LastTradeWithTime>Sep 15 - &lt;b&gt;38.18&lt;/b&gt;</LastTradeWithTime>
<LastTradePriceOnly>38.18</LastTradePriceOnly>
<HighLimit/>
<LowLimit/>
<DaysRange>37.77 - 38.25</DaysRange>
<DaysRangeRealtime>N/A - N/A</DaysRangeRealtime>
<FiftydayMovingAverage>37.8139</FiftydayMovingAverage>
<TwoHundreddayMovingAverage>44.0511</TwoHundreddayMovingAverage>
<ChangeFromTwoHundreddayMovingAverage>-5.8711</ChangeFromTwoHundreddayMovingAverage>
<PercentChangeFromTwoHundreddayMovingAverage>-13.33%</PercentChangeFromTwoHundreddayMovingAverage>
<ChangeFromFiftydayMovingAverage>+0.3661</ChangeFromFiftydayMovingAverage>
<PercentChangeFromFiftydayMovingAverage>+0.97%</PercentChangeFromFiftydayMovingAverage>
<Name>BP p.l.c. Common</Name>
<Notes>-</Notes>
<Open>38.08</Open>
<PreviousClose>38.52</PreviousClose>
<PricePaid/>
<ChangeinPercent>-0.88%</ChangeinPercent>
<PriceSales>0.42</PriceSales>
<PriceBook>1.41</PriceBook>
<ExDividendDate>May 5</ExDividendDate>
<PERatio/>
<DividendPayDate>Jun 21</DividendPayDate>
<PERatioRealtime/>
<PEGRatio>1.25</PEGRatio>
<PriceEPSEstimateCurrentYear>6.27</PriceEPSEstimateCurrentYear>
<PriceEPSEstimateNextYear>6.04</PriceEPSEstimateNextYear>
<Symbol>BP</Symbol>
<SharesOwned/>
<ShortRatio>0.80</ShortRatio>
<LastTradeTime>4:00pm</LastTradeTime>
<TickerTrend>&amp;nbsp;+-+=+-&amp;nbsp;</TickerTrend>
<OneyrTargetPrice>47.27</OneyrTargetPrice>
<Volume>6831680</Volume>
<HoldingsValue/>
<HoldingsValueRealtime/>
<YearRange>26.75 - 62.38</YearRange>
<DaysValueChange>- - -0.88%</DaysValueChange>
<DaysValueChangeRealtime>N/A - N/A</DaysValueChangeRealtime>
<StockExchange>NYSE</StockExchange>
<DividendYield>6.54</DividendYield>
<PercentChange>-0.88%</PercentChange>
</quote>
</results>
</query>

最佳答案

我认为 Yahoo 不提供 Java API。你必须create an XML schema ,然后使用 XML 库创建实体类(JAXB 或类似的)。也可以获取 JSON 格式的 YQL 数据,在这种情况下我会使用 Google GSON parser并手动创建实体类。

关于java - 解析来自 YQL 的 XML 响应的常用库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3723894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com