开发者

What is the common used library I should parse to following XML output?

Given output from YQL

<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
 开发者_如何学Python   yahoo:count="4" yahoo:created="2011-01-20T06:06:19Z" yahoo:lang="en-US">
    <results>
        <quote symbol="YHOO">
            <Ask>16.47</Ask>
            <AverageDailyVolume>17453900</AverageDailyVolume>
            <Bid/>
            <AskRealtime>16.47</AskRealtime>
            <BidRealtime>0.00</BidRealtime>
            <BookValue>9.277</BookValue>
            <Change_PercentChange>-0.189 - -1.15%</Change_PercentChange>
            <Change>-0.189</Change>
            <Commission/>
            <ChangeRealtime>-0.189</ChangeRealtime>
            <AfterHoursChangeRealtime>N/A - N/A</AfterHoursChangeRealtime>
            ...

I was wondering what is the common used library in Java I should use to parse the output, so that I can obtain quote for a selected stock?


There are many. Java has a DOM API, and some other common libraries for parsing or binding are:

  • JAXB
  • DOM4J
  • JDOM
  • Castor
  • JIBX
  • XStream

I'm pretty sure YQL also returns JSON. In which case, I would get JSON results and use something like GSON to parse them, which might be a little bit more flexible.


Just use the XML support that's built in: org.w3c.dom and java.xml, javax.xml.parsers et. al.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜