<mergentRecentEvents extractTime="02/10/2011 16:30:02"
beginTime="02/10/2011 01:00:00 PM" endTime="02/10/2011 04:30:00 PM">
<event eventAddDate="02/10/2011 13:13:25">
<eventGroupType>dividendsEvent</eventGroupType>
<titleCode>DIVP</titleCode>
<title>Dividend Payment</title>
<officialName>Globe Telecom Inc (Philippines)</officialName>
<issueDetail>
<countryCode>PHL</countryCode>
<issueDescription>Ord</issueDescription>
<issueType>Ordinary</issueType>
<primaryTicker>GTMEF</primaryTicker>
<primaryExchange>NBB</primaryExchange>
<identifiers>
<identifier Type="ISIN" Number="PHY272571498" />
</identifiers>
<cins>Y27257149</cins>
<status>A</status>
<lifeStage>Trading</lifeStage>
<iad>74</iad>
<dpfc>S</dpfc>
</issueDetail>
<termsAndConditions>
<companyInfo>
<issueDescription>Ord</issueDescription>
<ticker>GTMEF</ticker>
<exchangeCode>NBB</exchangeCode>
<cusip>Y27257149</cusip>
<paymentKey>0004146020</paymentKey>
<amount>31</amount>
<currencyCode>PHP</currencyCode>
<recordDate>2/22/2011</recordDate>
<payTypeList>
<payType>0</payType>
</payTypeList>
</companyInfo>
<footnoteList>
<footnote Code="406">
<footnoteLiteral>Not subject to PH withholding tax. </
footnoteLiteral>
</footnote>
<footnote Code="216">
<footnoteLiteral>Interim div. for fiscal year beginning
2011. </footnoteLiteral>
</footnote>
</footnoteList>
</termsAndConditions>
</event>
</mergentRecentEvents>
So anything that is just under the event tag, I can retrieve, but
anything that is deeper than that I get a null. For example, if I want
to get countryCode I can't pull it out.
<issueDetail>
<countryCode>PHL</countryCode>
<issueDescription>Ord</issueDescription>
<issueType>Ordinary</issueType>
<primaryTicker>GTMEF</primaryTicker>
<primaryExchange>NBB</primaryExchange>
<identifiers>
<identifier Type="ISIN" Number="PHY272571498" />
</identifiers>
<cins>Y27257149</cins>
<status>A</status>
<lifeStage>Trading</lifeStage>
<iad>74</iad>
<dpfc>S</dpfc>
</issueDetail>
Here is my sample code. Any help is appreciated.
This works:
SELECT tab.col.value('./eventGroupType[1]','varchar(50)') AS
'EventGroupType'
,tab.col.value('./titleCode[1]','varchar(50)') AS 'TitleCode'
,tab.col.value('./title[1]','varchar(50)') AS 'Title'
,tab.col.value('./officialName[1]','varchar(50)') AS 'OfficalName'
FROM [XmlImportTest]
CROSS APPLY
xml_data.nodes('//event') AS tab(col)
GO
This does not:
SELECT tab.col.value('./eventGroupType[1]','varchar(50)') AS
'EventGroupType'
,tab.col.value('./titleCode[1]','varchar(50)') AS 'TitleCode'
,tab.col.value('./title[1]','varchar(50)') AS 'Title'
,tab.col.value('./officialName[1]','varchar(50)') AS 'OfficalName'
,tab.col.value('./issueDetail/countryCode[1]','varchar(50)') AS
'CountryCode'
FROM [XmlImportTest]
CROSS APPLY
xml_data.nodes('//event') AS tab(col)
GO
Hi
Declare @x XML = '
<issueDetail>
<countryCode>PHL</countryCode>
<issueDescription>Ord</issueDescription>
<issueType>Ordinary</issueType>
<primaryTicker>GTMEF</primaryTicker>
<primaryExchange>NBB</primaryExchange>
<identifiers>
<identifier Type="ISIN" Number="PHY272571498" />
</identifiers>
<cins>Y27257149</cins>
<status>A</status>
<lifeStage>Trading</lifeStage>
<iad>74</iad>
<dpfc>S</dpfc>
</issueDetail>
'
select @x.value('./issueDetail/countryCode[1]','varchar(50)');
--Will fail : not a singleton
select @x.value('(./issueDetail/countryCode)[1]','varchar(50)');
--Wil work (just added parentesis)
Hope this helps
Patrick