将网站 XML-feed 导入 SQL Server

Import website XML-feed to SQL Server(将网站 XML-feed 导入 SQL Server)
本文介绍了将网站 XML-feed 导入 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

希望你们一切顺利.

我需要将 XML 源从网站导入到我的 SQL Server 数据库.我对 XML 不太了解.

I need to import an XML-feed from a website to my SQL Server database. I don't know much about XML.

Feed 结构有点复杂.这是该文件的示例:

The feed structure is an bit complex. Here is the sample of that file:

<line_feed>
<FeedTime>1279519582927</FeedTime>
<lastContest>4103839</lastContest>
<lastGame>58629754</lastGame>
<events>
<event>
    <event_datetimeGMT>2010-07-19 21:30</event_datetimeGMT>
    <gamenumber>174087393</gamenumber>
    <sporttype>Tennis</sporttype>
    <league>abc</league>
    <participants>
        <participant>
            <participant_name>R. Ram</participant_name>
            <contestantnum>4303</contestantnum>
            <rotnum>4303</rotnum>
            <visiting_home_draw>Visiting</visiting_home_draw>
        </participant>
        <participant>
            <participant_name>K. Beck</participant_name>
            <contestantnum>4304</contestantnum>
            <rotnum>4304</rotnum>
            <visiting_home_draw>Home</visiting_home_draw>
        </participant>
    </participants>
    <periods>
        <period>
            <period_number>0</period_number>
            <period_description>Game</period_description>
            <periodcutoff_datetimeGMT>2010-07-19 21:30</periodcutoff_datetimeGMT>
            <period_status>I</period_status>
            <period_update>open</period_update>
            <spread_maximum>250</spread_maximum>
            <moneyline_maximum>1500</moneyline_maximum>
            <total_maximum>250</total_maximum>
            <moneyline>
                <moneyline_visiting>135</moneyline_visiting>
                <moneyline_home>-146</moneyline_home>
            </moneyline>
        </period>
        <period>
            <period_number>0</period_number>
            <period_description>Game</period_description>
            <periodcutoff_datetimeGMT>2010-07-19 21:30</periodcutoff_datetimeGMT>
            <period_status>I</period_status>
            <period_update>open</period_update>
            <spread_maximum>250</spread_maximum>
            <moneyline_maximum>250</moneyline_maximum>
            <total_maximum>250</total_maximum>
            <spread>
                <spread_visiting>2</spread_visiting>
                <spread_adjust_visiting>101</spread_adjust_visiting>
                <spread_home>-2</spread_home>
                <spread_adjust_home>-118</spread_adjust_home>
            </spread>
            <total>
                <total_points>22.5</total_points>
                <over_adjust>-108</over_adjust>
                <under_adjust>-108</under_adjust>
            </total>
        </period>
        <period>
            <period_number>1</period_number>
            <period_description>1st Set</period_description>
            <periodcutoff_datetimeGMT>2010-07-19 21:30</periodcutoff_datetimeGMT>
            <period_status>I</period_status>
            <period_update>open</period_update>
            <spread_maximum>5000</spread_maximum>
            <moneyline_maximum>250</moneyline_maximum>
            <total_maximum>5000</total_maximum>
            <moneyline>
                <moneyline_visiting>114</moneyline_visiting>
                <moneyline_home>-133</moneyline_home>
            </moneyline>
        </period>
    </periods>
</event>
</events>
</line_feed>

能否请您帮帮我,我该如何将数据从该提要加载到 SQL Server.

Can you please help me out, how can I approach to load the data from that feed to SQL Server.

另请询问我是否需要了解此场景的任何其他详细信息.等待您的友好回复.

Please also ask me if any other details needed to understand this scenario. Awaiting your kind response.

谢谢,普拉桑特

推荐答案

如果您的 XML 格式良好,您可以将其存储在 xml 类型变量中.然后你可以使用 XPath 从中读取字段:

If your XML is wel-formed, you can store it in an xml type variable. Then you can use XPath to read fields from it:

declare @xml xml
set @xml = '
<line_feed>
<PinnacleFeedTime>1279519582927</PinnacleFeedTime>
...
'

select @xml.value('(line_feed/events/event/sporttype)[1]', 'VARCHAR(8000)')

这将打印Tennis.

这篇关于将网站 XML-feed 导入 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Query with t(n) and multiple cross joins(使用 t(n) 和多个交叉连接进行查询)
Unpacking a binary string with TSQL(使用 TSQL 解包二进制字符串)
Max rows in SQL table where PK is INT 32 when seed starts at max negative value?(当种子以最大负值开始时,SQL 表中的最大行数其中 PK 为 INT 32?)
Inner Join and Group By in SQL with out an aggregate function.(SQL 中的内部连接和分组依据,没有聚合函数.)
Add a default constraint to an existing field with values(向具有值的现有字段添加默认约束)
SQL remove from running total(SQL 从运行总数中删除)