【问题标题】:parsing xml with T-SQL.... what am i doing wrong用 T-SQL 解析 xml....我做错了什么
【发布时间】:2023-04-04 23:05:01
【问题描述】:

我正在尝试解析从 web 服务获得的 xml 信息,以便稍后放入表中。 我只有一个空字段没有错误,所以我可能忽略了一些小东西,有人能把我推向正确的方向吗?

Declare @myXml as xml;

set @myXml = '<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://www.webserviceX.NET">
   <CurrentWeather>
      <Location>Eindhoven, Netherlands (EHEH) 51-27N 005-25E 28M</Location>
      <Time>Jun 15, 2016 - 06:55 AM EDT / 2016.06.15 1055 UTC</Time>
      <Wind>from the WSW (240 degrees) at 2 MPH (2 KT):0</Wind>
      <Visibility>greater than 7 mile(s):0</Visibility>
      <SkyConditions>mostly cloudy</SkyConditions>
      <Temperature>62 F (17 C)</Temperature>
      <DewPoint>57 F (14 C)</DewPoint>
      <RelativeHumidity>82%</RelativeHumidity>
      <Pressure>29.50 in. Hg (0999 hPa)</Pressure>
      <Status>Success</Status>
   </CurrentWeather>
</string>';

 SELECT 
   b.value('(./CurrentWeather/Location/text())[1]','Varchar(250)') as [Location] 
FROM @myXml.nodes('/string') as a(b);

【问题讨论】:

标签: sql-server xml tsql


【解决方案1】:

T-SQL 要求您在存在命名空间时指定命名空间:

with xmlnamespaces(default 'http://www.webserviceX.NET')
select b.value('(./CurrentWeather/Location/text())[1]','Varchar(250)') as [Location]
FROM @myXml.nodes('/string') as a(b);

【讨论】:

    猜你喜欢
    • 2010-11-07
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多