English 中文(简体)
如何从xml饲料中获取数据
原标题:how to get the data from xml feeds

I have the following feeds from my vendor, http://scores.cricandcric.com/cricket/getFeed?key=4333433434343&format=xml&tagsformat=long&type=schedule

I wanted to get the data from that xml files as java objects, so that I can insert into my database regularly. The above data is nothing but regular updates from the vendor, so that I can update in my website.

请向我建议,我可以选择哪些办法来开展这项工作。

Should I use any webservices or just Xstream to get my final output.. please suggest me as am a new comer to this concept

供应商建议我,他可以向我提供以下3种格式的器、xml或json的数据,我不相信什么是轻而易的,可以让我工作。

问题回答

我只想写出一个方案,把XML同起来,并将数据直接输入你的数据库。

Example

The groovy script.” rel=“nofollow” H2 数据库。

// 
// Dependencies
// ============
import groovy.sql.Sql

@Grapes([
    @Grab(group= com.h2database , module= h2 , version= 1.3.163 ),
    @GrabConfig(systemClassLoader=true)
])

//
// Main program
// ============
def sql = Sql.newInstance("jdbc:h2:db/cricket", "user", "pass", "org.h2.Driver") 

def dataUrl = new URL("http://scores.cricandcric.com/cricket/getFeed?key=4333433434343&format=xml&tagsformat=long&type=schedule")

dataUrl.withReader { reader ->
    def feeds = new XmlSlurper().parse(reader)

    feeds.matches.match.each {
        def data = [
            it.id,
            it.name,
            it.type,
            it.tournamentId,
            it.location,
            it.date,
            it.GMTTime,
            it.localTime,
            it.description,
            it.team1,
            it.team2,
            it.teamId1,
            it.teamId2,
            it.tournamentName,
            it.logo
        ].collect {
            it.text()
        }

        sql.execute("INSERT INTO matches (id,name,type,tournamentId,location,date,GMTTime,localTime,description,team1,team2,teamId1,teamId2,tournamentName,logo) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", data)
    }
}

......你可以使用XML Parser(溪流或多氧化二氮),也可以使用JSON教区(DOM的溪流),并在飞机上建树。 但是,这些数据似乎包括板球配对记录,为什么不采用碎格式?

这似乎是你的基本 da子:

<id>1263</id>
<name>Australia v India 3rd Test at  Perth - Jan 13-17, 2012</name>
<type>TestMatch</type>
<tournamentId>137</tournamentId>
<location>Perth</location>
<date>2012-01-14</date>
<GMTTime>02:30:00</GMTTime>
<localTime>10:30:00</localTime>
<description>3rd Test day 2</description>
<team1>Australia</team1>
<team2>India</team2>
<teamId1>7</teamId1>
<teamId2>1</teamId2>
<tournamentName>India tour of Australia 2011-12</tournamentName>
<logo>/cricket/137/tournament.png</logo>

当然,你仍然必须打上头巾,处理限定性的问题(例如,如果你有或“有str”,但会大大减少你的网络交通,并很可能使客户更快地陷入困境。 当然,这取决于你的客户。

Actually you have RESTful store that can return data in several formats and you only need to read from this source and no further interaction is needed. So, you can use any XML Parser to parse XML data and put the extracted data in whatever data structure that you want or you have.

我没有听说过XTREME的话,但你可以找到更多信息,了解如何在上选择最优等舱位。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签