Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / еще один XML / 7 сообщений из 7, страница 1 из 1
08.05.2019, 10:59
    #39811161
komrad
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
Коллеги, помогите плз достать следующие значения из приложенного XML.
Все мои варианты не выдают ничего :(

/Triplist/Trip idx
/Triplist/Trip/SeviceDays sDaysR
/Triplist/Trip/LegList/Leg direction

заранее спасибо )

большой XML и запрос
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
declare @x xml 
set @x = N'<TripList xmlns="hafas_rest" serverVersion="1.13-SNAPSHOT" dialectVersion="1.23" >
  <Trip idx="0" checksum="7d9389e2_3" tripId="C-0" duration="PT1H27M">
    <ServiceDays sDaysR="Vr" planningPeriodBegin="2018-12-09" planningPeriodEnd="2019-12-14" />
    <LegList>
      <Leg type="JNY" idx="0" name="SPR 6418" number="6418" category="SPR" reachable="true" direction="Tilburg">
        <Origin type="ST" routeIdx="3" date="2019-04-12" time="05:38:00" tz="120" track="1" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station A</Note>
            <Note key="SH" priority="0" type="A">Station B</Note>
            <Note key="SS" priority="0" type="A">Station R</Note>
            <Note key="EK" type="I">gp</Note>
          </Notes>
        </Origin>
        <Destination type="ST" routeIdx="4" date="2019-04-12" time="05:43:00" tz="120" track="4" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Destination>
        <Notes>
          <Note routeIdxFrom="3" routeIdxTo="3" key="ES" priority="0" type="A">+eas, TPSI</Note>
          <Note routeIdxFrom="4" routeIdxTo="4" key="ES" priority="0" type="A">+eas, TPSI</Note>
        </Notes>
        <JourneyDetailRef ref="1|3246|0|684|12042019" />
        <JourneyStatus>P</JourneyStatus>
        <Product catCode="3" catIn="SPR" catOut="SPR     " catOutL="Sprinter" catOutS="SPR" line="" name="SPR 6418" num="6418" operator="NS" operatorCode="ns " admin="100___" />
      </Leg>
      <Leg type="WALK" idx="1" dist="0" duration="PT4M" name="">
        <Origin type="ST" date="2019-04-12" time="05:43:00" tz="120">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Origin>
        <Destination type="ST" date="2019-04-12" time="05:47:00" tz="120">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station B</Note>
            <Note key="SS" priority="0" type="A">Station A</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Destination>
        <GisRef ref="H|1|W$A=1@O=...@L=1100896@a=128@$201904120543$201904120547$$$1$" />
      </Leg>
      <Leg type="JNY" idx="2" name="IC 3516 " number="3516" category="IC" reachable="true" direction="Barnaul Airport">
        <Origin type="ST" routeIdx="0" date="2019-04-12" time="05:47:00" tz="120" track="6" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station B</Note>
            <Note key="SS" priority="0" type="A">Station A</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Origin>
        <Destination type="ST" routeIdx="13" date="2019-04-12" time="06:35:00" tz="120" track="7" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SS" priority="0" type="A">Station A</Note>
            <Note key="EK" type="I">ut</Note>
          </Notes>
        </Destination>
        <Notes>
          <Note routeIdxFrom="0" routeIdxTo="0" key="ES" priority="0" type="A">+eas, TPSI</Note>
          <Note routeIdxFrom="13" routeIdxTo="13" key="ES" priority="0" type="A">+eas, TPSI</Note>
        </Notes>
        <JourneyDetailRef ref="1|515713|0|684|12042019" />
        <JourneyStatus>P</JourneyStatus>
        <Product catCode="1" catIn="IC" catOut="IC      " catOutL="Intercity" catOutS="IC" line="" name="IC 3516 " num="3516" operator="NS" operatorCode="ns " admin="100___" />
      </Leg>
      <Leg type="WALK" idx="3" dist="0" duration="PT2M" name="">
        <Origin type="ST" date="2019-04-12" time="06:35:00" tz="120">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SS" priority="0" type="A">Station A</Note>
            <Note key="EK" type="I">ut</Note>
          </Notes>
        </Origin>
        <Destination type="ST" date="2019-04-12" time="06:37:00" tz="120">
          <Notes>
            <Note key="IS" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station R</Note>
            <Note key="EK" type="I">ut</Note>
          </Notes>
        </Destination>
        <GisRef ref="H|1|W$A=1@O=...@a=128@$201904120635$201904120637$$$1$" />
      </Leg>
      <Leg type="JNY" idx="4" name="IC 3014 " number="3014" category="IC" reachable="true" direction="Helder">
        <Origin type="ST" routeIdx="13" date="2019-04-12" time="06:38:00" tz="120" track="5" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">ut</Note>
          </Notes>
        </Origin>
        <Destination type="ST" routeIdx="23" date="2019-04-12" time="07:05:00" tz="120" track="8a" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">asd</Note>
          </Notes>
        </Destination>
        <Notes>
          <Note routeIdxFrom="13" routeIdxTo="13" key="ES" priority="0" type="A">+eas, TPSI</Note>
          <Note routeIdxFrom="23" routeIdxTo="23" key="ES" priority="0" type="A">+eas, TPSI</Note>
        </Notes>
        <JourneyDetailRef ref="1|515057|0|684|12042019" />
        <JourneyStatus>P</JourneyStatus>
        <Product catCode="1" catIn="IC" catOut="IC      " catOutL="Intercity" catOutS="IC" line="" name="IC 3014 " num="3014" operator="NS" operatorCode="ns " admin="100___" />
      </Leg>
    </LegList>
  </Trip>
  <Trip idx="1" checksum="e65ce839_3" tripId="C-1" duration="PT1H41M">
    <ServiceDays sDaysR="Vr" planningPeriodBegin="2018-12-09" planningPeriodEnd="2019-12-14" />
    <LegList>
      <Leg type="JNY" idx="0" name="SPR 6418" number="6418" category="SPR" reachable="true" direction="Tilburg">
        <Origin type="ST" routeIdx="3" date="2019-04-12" time="05:38:00" tz="120" track="1" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">gp</Note>
          </Notes>
        </Origin>
        <Destination type="ST" routeIdx="4" date="2019-04-12" time="05:43:00" tz="120" track="4" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Destination>
        <Notes>
          <Note routeIdxFrom="3" routeIdxTo="3" key="ES" priority="0" type="A">+eas, TPSI</Note>
          <Note routeIdxFrom="4" routeIdxTo="4" key="ES" priority="0" type="A">+eas, TPSI</Note>
        </Notes>
        <JourneyDetailRef ref="1|3246|0|684|12042019" />
        <JourneyStatus>P</JourneyStatus>
        <Product catCode="3" catIn="SPR" catOut="SPR     " catOutL="Sprinter" catOutS="SPR" line="" name="SPR 6418" num="6418" operator="NS" operatorCode="ns " admin="100___" />
      </Leg>
      <Leg type="JNY" idx="1" name="IC 2916 " number="2916" category="IC" reachable="true" direction="AlmaAta">
        <Origin type="ST" routeIdx="0" date="2019-04-12" time="06:04:00" tz="120" track="4" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">ehv</Note>
          </Notes>
        </Origin>
        <Destination type="ST" routeIdx="23" date="2019-04-12" time="07:19:00" tz="120" track="8a" prognosisType="PROGNOSED">
          <Notes>
            <Note key="IS" priority="0" type="A">Station R</Note>
            <Note key="SH" priority="0" type="A">Station A</Note>
            <Note key="SS" priority="0" type="A">Station B</Note>
            <Note key="EK" type="I">asd</Note>
          </Notes>
        </Destination>
        <Notes>
          <Note routeIdxFrom="0" routeIdxTo="0" key="ES" priority="0" type="A">+eas, TPSI</Note>
          <Note routeIdxFrom="23" routeIdxTo="23" key="ES" priority="0" type="A">+eas, TPSI</Note>
        </Notes>
        <JourneyDetailRef ref="1|514769|0|684|12042019" />
        <JourneyStatus>P</JourneyStatus>
        <Product catCode="1" catIn="IC" catOut="IC      " catOutL="Intercity" catOutS="IC" line="" name="IC 2916 " num="2916" operator="NS" operatorCode="ns " admin="100___" />
      </Leg>
    </LegList>
  </Trip>
</TripList>'

select 
	x.content.value('(@idx)[1]', 'int') [Idx]

from (select @x) as q(x) 
cross apply x.nodes('Triplist/Trip') as  x(content);

...
Рейтинг: 0 / 0
08.05.2019, 11:17
    #39811171
Посетитель
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
komrad,

как вариант
Код: sql
1.
with xmlnamespaces(default  'hafas_rest')



ну и учтите, что "Triplist" и "TripList" - не одно и то же
...
Рейтинг: 0 / 0
08.05.2019, 11:19
    #39811173
еще один XML
XML если что регистрозависимый:

Код: sql
1.
2.
SELECT t.c.value('(@idx)[1]', 'INT')
FROM @x.nodes('*:TripList/*:Trip') t(c)
...
Рейтинг: 0 / 0
08.05.2019, 13:53
    #39811284
komrad
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
Sergey SyrovatchenkoXML если что регистрозависимый:

Код: sql
1.
2.
SELECT t.c.value('(@idx)[1]', 'INT')
FROM @x.nodes('*:TripList/*:Trip') t(c)


спасибо за верное направление!
...
Рейтинг: 0 / 0
08.05.2019, 13:56
    #39811287
komrad
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
Посетительkomrad,

как вариант
Код: sql
1.
with xmlnamespaces(default  'hafas_rest')



ну и учтите, что "Triplist" и "TripList" - не одно и то же
а как будет выглядеть запрос в данном случае?
простая подстановка в начало не сработала...
...
Рейтинг: 0 / 0
08.05.2019, 13:58
    #39811292
Посетитель
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
komradПосетительkomrad,

как вариант
Код: sql
1.
with xmlnamespaces(default  'hafas_rest')




ну и учтите, что "Triplist" и "TripList" - не одно и то же
а как будет выглядеть запрос в данном случае?
простая подстановка в начало не сработала...

потому что надо было учесть вот это

Посетитель
ну и учтите, что "Triplist" и "TripList" - не одно и то же

Код: sql
1.
2.
3.
4.
5.
6.
;with xmlnamespaces(default  'hafas_rest')
select 
	x.content.value('(@idx)[1]', 'int') [Idx]

from (select @x) as q(x) 
cross apply x.nodes('TripList/Trip') as  x(content);
...
Рейтинг: 0 / 0
08.05.2019, 15:15
    #39811378
komrad
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
еще один XML
Посетитель,

спасибо! )
...
Рейтинг: 0 / 0
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / еще один XML / 7 сообщений из 7, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]